Revision 889bed16 qa/qa_utils.py
b/qa/qa_utils.py | ||
---|---|---|
133 | 133 |
raise qa_error.Error("%r doesn't match /%r/" % (string, pattern)) |
134 | 134 |
|
135 | 135 |
|
136 |
def _GetName(entity, key): |
|
137 |
"""Tries to get name of an entity. |
|
138 |
|
|
139 |
@type entity: string or dict |
|
140 |
@type key: string |
|
141 |
@param key: Dictionary key containing name |
|
142 |
|
|
143 |
""" |
|
144 |
if isinstance(entity, basestring): |
|
145 |
result = entity |
|
146 |
elif isinstance(entity, dict): |
|
147 |
result = entity[key] |
|
148 |
else: |
|
149 |
raise qa_error.Error("Expected string or dictionary, got %s: %s" % |
|
150 |
(type(entity), entity)) |
|
151 |
|
|
152 |
if not ht.TNonEmptyString(result): |
|
153 |
raise Exception("Invalid name '%s'" % result) |
|
154 |
|
|
155 |
return result |
|
156 |
|
|
157 |
|
|
136 | 158 |
def AssertCommand(cmd, fail=False, node=None): |
137 | 159 |
"""Checks that a remote command succeeds. |
138 | 160 |
|
... | ... | |
148 | 170 |
if node is None: |
149 | 171 |
node = qa_config.GetMasterNode() |
150 | 172 |
|
151 |
if isinstance(node, basestring): |
|
152 |
nodename = node |
|
153 |
else: |
|
154 |
nodename = node["primary"] |
|
173 |
nodename = _GetName(node, "primary") |
|
155 | 174 |
|
156 | 175 |
if isinstance(cmd, basestring): |
157 | 176 |
cmdstr = cmd |
... | ... | |
544 | 563 |
"""Check if instance is running or not. |
545 | 564 |
|
546 | 565 |
""" |
547 |
if isinstance(instance, basestring): |
|
548 |
instance_name = instance |
|
549 |
else: |
|
550 |
instance_name = instance["name"] |
|
551 |
|
|
552 |
if not ht.TNonEmptyString(instance_name): |
|
553 |
raise Exception("Invalid instance name '%s'" % instance_name) |
|
566 |
instance_name = _GetName(instance, "name") |
|
554 | 567 |
|
555 | 568 |
script = qa_config.GetInstanceCheckScript() |
556 | 569 |
if not script: |
Also available in: Unified diff