Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite44aa98

Browse files
RemoteOperations::exec_command explicitly transfers LANG, LANGUAGE and LC_* envvars to the server side (#187)
* RemoteOperations::exec_command updated- Exact enumeration of supported 'cmd' types- Refactoring* RemoteOperations::exec_command explicitly transfers LANG, LANGUAGE and LC_* envvars to the server sideIt should help resolve a problem with replacing a LANG variable by ssh-server.History.On our internal tests we got a problem on the Debian 11 and PostgresPro STD-13.One test returned the error from initdb:initdb: error: collations with different collate and ctype values ("en_US.UTF-8" and "C.UTF-8" accordingly) are not supported by ICU- TestRunner set variable LANG="C"- Python set variable LC_CTYPE="C.UTF-8"- Test call inidb through command "ssh test@localhost inidb -D ...."- SSH-server replaces LANG with value "en_US.UTF-8" (from etc/default/locale)- initdb calculate collate through this value of LANG variable and get en_US.UTF-8So we have that:- ctype is C.UTF-8- collate is en_US.UTF-8ICU on the Debuan-11 (uconv v2.1 ICU 67.1) does not suppot this combination and inidb rturns the error.This patch generates a new command line for ssh:ssh test@localhost "LANG=\"...\";LC_xxx=\"...\";<command>"It resolves this problem with initdb and should help resolve other problems with execution of command through SSH.Amen.* New tests in TestgresRemoteTests are addedNew tests: - test_init__LANG_С - test_init__unk_LANG_and_LC_CTYPE* TestgresRemoteTests.test_init__unk_LANG_and_LC_CTYPE is updatedLet's test bad data with '\' and '"' symbols.* Static methods are marked with@staticmethod [thanks to Victoria Shepard]The following methods of RemoteOperations were corrected: - _make_exec_env_list - _does_put_envvar_into_exec_cmd - _quote_envvar* TestRemoteOperations::_quote_envvar is updated (typification)
1 parent7fd2f07 commite44aa98

File tree

2 files changed

+124
-1
lines changed

2 files changed

+124
-1
lines changed

‎testgres/operations/remote_ops.py

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,12 @@ def exec_command(self, cmd, wait_exit=False, verbose=False, expect_error=False,
8787

8888
asserttype(cmd_s)==str# noqa: E721
8989

90-
ssh_cmd= ['ssh',self.ssh_dest]+self.ssh_args+ [cmd_s]
90+
cmd_items=__class__._make_exec_env_list()
91+
cmd_items.append(cmd_s)
92+
93+
env_cmd_s=';'.join(cmd_items)
94+
95+
ssh_cmd= ['ssh',self.ssh_dest]+self.ssh_args+ [env_cmd_s]
9196

9297
process=subprocess.Popen(ssh_cmd,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
9398
assertnot (processisNone)
@@ -510,6 +515,45 @@ def db_connect(self, dbname, user, password=None, host="localhost", port=5432):
510515
)
511516
returnconn
512517

518+
@staticmethod
519+
def_make_exec_env_list()->list[str]:
520+
result=list[str]()
521+
forenvvarinos.environ.items():
522+
ifnot__class__._does_put_envvar_into_exec_cmd(envvar[0]):
523+
continue
524+
qvalue=__class__._quote_envvar(envvar[1])
525+
asserttype(qvalue)==str# noqa: E721
526+
result.append(envvar[0]+"="+qvalue)
527+
continue
528+
529+
returnresult
530+
531+
sm_envs_for_exec_cmd= ["LANG","LANGUAGE"]
532+
533+
@staticmethod
534+
def_does_put_envvar_into_exec_cmd(name:str)->bool:
535+
asserttype(name)==str# noqa: E721
536+
name=name.upper()
537+
ifname.startswith("LC_"):
538+
returnTrue
539+
ifnamein__class__.sm_envs_for_exec_cmd:
540+
returnTrue
541+
returnFalse
542+
543+
@staticmethod
544+
def_quote_envvar(value:str)->str:
545+
asserttype(value)==str# noqa: E721
546+
result="\""
547+
forchinvalue:
548+
ifch=="\"":
549+
result+="\\\""
550+
elifch=="\\":
551+
result+="\\\\"
552+
else:
553+
result+=ch
554+
result+="\""
555+
returnresult
556+
513557

514558
defnormalize_error(error):
515559
ifisinstance(error,bytes):

‎tests/test_simple_remote.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,79 @@ def test_custom_init(self):
119119
# there should be no trust entries at all
120120
self.assertFalse(any('trust'insforsinlines))
121121

122+
deftest_init__LANG_С(self):
123+
# PBCKP-1744
124+
prev_LANG=os.environ.get("LANG")
125+
126+
try:
127+
os.environ["LANG"]="C"
128+
129+
withget_remote_node(conn_params=conn_params)asnode:
130+
node.init().start()
131+
finally:
132+
__class__.helper__restore_envvar("LANG",prev_LANG)
133+
134+
deftest_init__unk_LANG_and_LC_CTYPE(self):
135+
# PBCKP-1744
136+
prev_LANG=os.environ.get("LANG")
137+
prev_LANGUAGE=os.environ.get("LANGUAGE")
138+
prev_LC_CTYPE=os.environ.get("LC_CTYPE")
139+
prev_LC_COLLATE=os.environ.get("LC_COLLATE")
140+
141+
try:
142+
# TODO: Pass unkData through test parameter.
143+
unkDatas= [
144+
("UNKNOWN_LANG","UNKNOWN_CTYPE"),
145+
("\"UNKNOWN_LANG\"","\"UNKNOWN_CTYPE\""),
146+
("\\UNKNOWN_LANG\\","\\UNKNOWN_CTYPE\\"),
147+
("\"UNKNOWN_LANG","UNKNOWN_CTYPE\""),
148+
("\\UNKNOWN_LANG","UNKNOWN_CTYPE\\"),
149+
("\\","\\"),
150+
("\"","\""),
151+
]
152+
153+
forunkDatainunkDatas:
154+
logging.info("----------------------")
155+
logging.info("Unk LANG is [{0}]".format(unkData[0]))
156+
logging.info("Unk LC_CTYPE is [{0}]".format(unkData[1]))
157+
158+
os.environ["LANG"]=unkData[0]
159+
os.environ.pop("LANGUAGE",None)
160+
os.environ["LC_CTYPE"]=unkData[1]
161+
os.environ.pop("LC_COLLATE",None)
162+
163+
assertos.environ.get("LANG")==unkData[0]
164+
assertnot ("LANGUAGE"inos.environ.keys())
165+
assertos.environ.get("LC_CTYPE")==unkData[1]
166+
assertnot ("LC_COLLATE"inos.environ.keys())
167+
168+
whileTrue:
169+
try:
170+
withget_remote_node(conn_params=conn_params):
171+
pass
172+
excepttestgres.exceptions.ExecUtilExceptionase:
173+
#
174+
# Example of an error message:
175+
#
176+
# warning: setlocale: LC_CTYPE: cannot change locale (UNKNOWN_CTYPE): No such file or directory
177+
# postgres (PostgreSQL) 14.12
178+
#
179+
errMsg=str(e)
180+
181+
logging.info("Error message is: {0}".format(errMsg))
182+
183+
assert"LC_CTYPE"inerrMsg
184+
assertunkData[1]inerrMsg
185+
assert"warning: setlocale: LC_CTYPE: cannot change locale ("+unkData[1]+"): No such file or directory"inerrMsg
186+
assert"postgres"inerrMsg
187+
break
188+
raiseException("We expected an error!")
189+
finally:
190+
__class__.helper__restore_envvar("LANG",prev_LANG)
191+
__class__.helper__restore_envvar("LANGUAGE",prev_LANGUAGE)
192+
__class__.helper__restore_envvar("LC_CTYPE",prev_LC_CTYPE)
193+
__class__.helper__restore_envvar("LC_COLLATE",prev_LC_COLLATE)
194+
122195
deftest_double_init(self):
123196
withget_remote_node(conn_params=conn_params).init()asnode:
124197
# can't initialize node more than once
@@ -994,6 +1067,12 @@ def test_child_process_dies(self):
9941067
# try to handle children list -- missing processes will have ptype "ProcessType.Unknown"
9951068
[ProcessProxy(p)forpinchildren]
9961069

1070+
defhelper__restore_envvar(name,prev_value):
1071+
ifprev_valueisNone:
1072+
os.environ.pop(name,None)
1073+
else:
1074+
os.environ[name]=prev_value
1075+
9971076

9981077
if__name__=='__main__':
9991078
ifos_ops.environ('ALT_CONFIG'):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp