diff options
author | Jing Lu <lvjing5@huawei.com> | 2017-02-16 09:36:46 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2017-02-16 09:36:46 +0000 |
commit | 67b8280f53646fb268bc1e2fbe166173419bbd88 (patch) | |
tree | b1b72060729ed180fe24b9e3491961b3fb71cb28 | |
parent | dd8ca59fd7421a1f362e50f0d3413a903761d179 (diff) | |
parent | cc3f02db3c337ba441c69f8f852566b7f402e850 (diff) |
Merge "Bugfix: AttributeError: 'dict' object has no attribute 'encode'"
-rw-r--r-- | tests/unit/benchmark/core/test_task.py | 24 | ||||
-rw-r--r-- | yardstick/benchmark/core/task.py | 22 |
2 files changed, 43 insertions, 3 deletions
diff --git a/tests/unit/benchmark/core/test_task.py b/tests/unit/benchmark/core/test_task.py index c56e21047..cd7ffdebb 100644 --- a/tests/unit/benchmark/core/test_task.py +++ b/tests/unit/benchmark/core/test_task.py @@ -155,6 +155,30 @@ class TaskTestCase(unittest.TestCase): self.assertEqual(task_args_fnames[0], None) self.assertEqual(task_args_fnames[1], None) + def test_change_server_name_host_str(self): + scenario = {'host': 'demo'} + suffix = '-8' + task.change_server_name(scenario, suffix) + self.assertTrue(scenario['host'], 'demo-8') + + def test_change_server_name_host_dict(self): + scenario = {'host': {'name': 'demo'}} + suffix = '-8' + task.change_server_name(scenario, suffix) + self.assertTrue(scenario['host']['name'], 'demo-8') + + def test_change_server_name_target_str(self): + scenario = {'target': 'demo'} + suffix = '-8' + task.change_server_name(scenario, suffix) + self.assertTrue(scenario['target'], 'demo-8') + + def test_change_server_name_target_dict(self): + scenario = {'target': {'name': 'demo'}} + suffix = '-8' + task.change_server_name(scenario, suffix) + self.assertTrue(scenario['target']['name'], 'demo-8') + def _get_file_abspath(self, filename): curr_path = os.path.dirname(os.path.abspath(__file__)) file_path = os.path.join(curr_path, filename) diff --git a/yardstick/benchmark/core/task.py b/yardstick/benchmark/core/task.py index 87d70f42f..5a52cdb11 100644 --- a/yardstick/benchmark/core/task.py +++ b/yardstick/benchmark/core/task.py @@ -355,10 +355,16 @@ def atexit_handler(): def is_ip_addr(addr): """check if string addr is an IP address""" try: + addr = addr.get('public_ip_attr', addr.get('private_ip_attr')) + except AttributeError: + pass + + try: ipaddress.ip_address(addr.encode('utf-8')) - return True except ValueError: return False + else: + return True def _is_same_heat_context(host_attr, target_attr): @@ -499,14 +505,24 @@ def check_environment(): def change_server_name(scenario, suffix): try: - scenario['host'] += suffix + host = scenario['host'] except KeyError: pass + else: + try: + host['name'] += suffix + except TypeError: + scenario['host'] += suffix try: - scenario['target'] += suffix + target = scenario['target'] except KeyError: pass + else: + try: + target['name'] += suffix + except TypeError: + scenario['target'] += suffix try: key = 'targets' |