Revision 31fe5102
b/lib/cmdlib.py | ||
---|---|---|
5528 | 5528 |
hostname = netutils.GetHostname(name=new_name) |
5529 | 5529 |
self.LogInfo("Resolved given name '%s' to '%s'", new_name, |
5530 | 5530 |
hostname.name) |
5531 |
if not utils.MatchNameComponent(self.op.new_name, [hostname.name]): |
|
5532 |
raise errors.OpPrereqError(("Resolved hostname '%s' does not look the" |
|
5533 |
" same as given hostname '%s'") % |
|
5534 |
(hostname.name, self.op.new_name), |
|
5535 |
errors.ECODE_INVAL) |
|
5531 | 5536 |
new_name = self.op.new_name = hostname.name |
5532 | 5537 |
if (self.op.ip_check and |
5533 | 5538 |
netutils.TcpPing(hostname.ip, constants.DEFAULT_NODED_PORT)): |
b/qa/qa_instance.py | ||
---|---|---|
148 | 148 |
_CheckSsconfInstanceList(rename_source) |
149 | 149 |
AssertCommand(["gnt-instance", "rename", rename_source, rename_target]) |
150 | 150 |
_CheckSsconfInstanceList(rename_target) |
151 |
AssertCommand(["gnt-instance", "rename", rename_target, rename_source]) |
|
152 |
_CheckSsconfInstanceList(rename_source) |
|
153 |
qa_utils.AddToEtcHosts(["meeeeh-not-exists", rename_target]) |
|
154 |
try: |
|
155 |
AssertCommand(["gnt-instance", "rename", rename_source, rename_target], |
|
156 |
fail=True) |
|
157 |
_CheckSsconfInstanceList(rename_source) |
|
158 |
finally: |
|
159 |
qa_utils.RemoveFromEtcHosts(["meeeeh-not-exists", rename_target]) |
|
160 |
AssertCommand(["gnt-instance", "rename", rename_source, rename_target]) |
|
161 |
_CheckSsconfInstanceList(rename_target) |
|
151 | 162 |
|
152 | 163 |
|
153 | 164 |
def TestInstanceFailover(instance): |
b/qa/qa_utils.py | ||
---|---|---|
470 | 470 |
FormatWarning = lambda text: _FormatWithColor(text, _WARNING_SEQ) |
471 | 471 |
FormatError = lambda text: _FormatWithColor(text, _ERROR_SEQ) |
472 | 472 |
FormatInfo = lambda text: _FormatWithColor(text, _INFO_SEQ) |
473 |
|
|
474 |
|
|
475 |
def AddToEtcHosts(hostnames): |
|
476 |
"""Adds hostnames to /etc/hosts. |
|
477 |
|
|
478 |
@param hostnames: List of hostnames first used A records, all other CNAMEs |
|
479 |
|
|
480 |
""" |
|
481 |
master = qa_config.GetMasterNode() |
|
482 |
tmp_hosts = UploadData(master["primary"], "", mode=0644) |
|
483 |
|
|
484 |
quoted_tmp_hosts = utils.ShellQuote(tmp_hosts) |
|
485 |
data = [] |
|
486 |
for localhost in ("::1", "127.0.0.1"): |
|
487 |
data.append("%s %s" % (localhost, " ".join(hostnames))) |
|
488 |
|
|
489 |
try: |
|
490 |
AssertCommand(("cat /etc/hosts > %s && echo -e '%s' >> %s && mv %s" |
|
491 |
" /etc/hosts") % (quoted_tmp_hosts, "\\n".join(data), |
|
492 |
quoted_tmp_hosts, quoted_tmp_hosts)) |
|
493 |
except qa_error.Error: |
|
494 |
AssertCommand(["rm", tmp_hosts]) |
|
495 |
|
|
496 |
|
|
497 |
def RemoveFromEtcHosts(hostnames): |
|
498 |
"""Remove hostnames from /etc/hosts. |
|
499 |
|
|
500 |
@param hostnames: List of hostnames first used A records, all other CNAMEs |
|
501 |
|
|
502 |
""" |
|
503 |
master = qa_config.GetMasterNode() |
|
504 |
tmp_hosts = UploadData(master["primary"], "", mode=0644) |
|
505 |
quoted_tmp_hosts = utils.ShellQuote(tmp_hosts) |
|
506 |
|
|
507 |
sed_data = " ".join(hostnames) |
|
508 |
try: |
|
509 |
AssertCommand(("sed -e '/^\(::1\|127\.0\.0\.1\)\s\+%s/d' /etc/hosts > %s" |
|
510 |
" && mv %s /etc/hosts") % (sed_data, quoted_tmp_hosts, |
|
511 |
quoted_tmp_hosts)) |
|
512 |
except qa_error.Error: |
|
513 |
AssertCommand(["rm", tmp_hosts]) |
Also available in: Unified diff