From c2ca2ed7066e5d6f82042a0b80d9d14403642208 Mon Sep 17 00:00:00 2001 From: Alexandr Kostrikov Date: Mon, 19 Sep 2016 19:42:26 +0300 Subject: [PATCH] Configdb changes alignment in autotests There were problems with changed format and missed functions. Change-Id: I1e1466f4565279107d172a72fffcc86e33c39b1b Closes-bug: 1623154 --- .../tests/tests_configdb/test_configdb_cli.py | 201 ++++++++---------- 1 file changed, 90 insertions(+), 111 deletions(-) diff --git a/fuelweb_test/tests/tests_configdb/test_configdb_cli.py b/fuelweb_test/tests/tests_configdb/test_configdb_cli.py index 993a2a91a..b26341778 100644 --- a/fuelweb_test/tests/tests_configdb/test_configdb_cli.py +++ b/fuelweb_test/tests/tests_configdb/test_configdb_cli.py @@ -11,7 +11,6 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -import json import operator import functools @@ -40,6 +39,7 @@ class TestsConfigDBAPI(TestBasic): @test(depends_on_groups=['create_component_and_env_configdb'], groups=['configdb_cli_interface']) + @log_snapshot_after_test def validate_creation_of_component(self): """Validate CRUD operations on components and resource definitions @@ -70,33 +70,28 @@ class TestsConfigDBAPI(TestBasic): list_component_cmd = 'fuel2 config comp list --format json' list_cmd_out = self.ssh_manager.check_call( self.ssh_manager.admin_ip, - list_component_cmd)['stdout_str'] - actual_component = [c for c in json.loads(list_cmd_out) if + list_component_cmd).stdout_json + actual_component = [c for c in list_cmd_out if c['name'] == u'empty'][0] assert_equal(actual_component['resource_definitions'], []) assert_equal(actual_component['name'], 'empty') self.show_step(4) # Verify failure of duplicate creation create_duplicate = 'fuel2 config comp create --name empty' - # TODO(akostrikov) return ec!=0 - # TODO(akostrikov) stderr? stdout = self.ssh_manager.check_call( self.ssh_manager.admin_ip, create_duplicate, - raise_on_err=False)['stdout_str'] + raise_on_err=False).stdout_str assert_true('duplicate key value violates unique constraint' in stdout) - # TODO(akostrikov) create comp cmd help more productive - # TODO(akostrikov) create component with resource definitions! - # TODO(akostrikov) component show by name self.show_step(5) # Create component to store resource definitions create_with_resources = 'fuel2 config comp create --name res' self.ssh_manager.check_call(admin_ip, create_with_resources) list_component_cmd = 'fuel2 config comp list --format json' list_cmd_out = self.ssh_manager.check_call( admin_ip, - list_component_cmd)['stdout_str'] - res_comp = [c for c in json.loads(list_cmd_out) if + list_component_cmd).stdout_json + res_comp = [c for c in list_cmd_out if c['name'] == 'res'][0] assert_equal(res_comp['resource_definitions'], []) res_id = res_comp['id'] @@ -115,10 +110,9 @@ class TestsConfigDBAPI(TestBasic): self.show_step(8) # Verify resources of the component show_comp_cmd = 'fuel2 config comp show {id} --format json'.format( id=res_id) - show_comp_out = self.ssh_manager.check_call( + component = self.ssh_manager.check_call( self.ssh_manager.admin_ip, - show_comp_cmd)['stdout_str'] - component = json.loads(show_comp_out) + show_comp_cmd).stdout_json res_def = component['resource_definitions'][0] assert_equal(res_def['content'], EXPECTED_RES_DEF['content']) @@ -159,14 +153,12 @@ class TestsConfigDBAPI(TestBasic): self.show_step(2) # Create environment with level create_env_cmd = 'fuel2 config env create -l servers' self.ssh_manager.check_call(self.ssh_manager.admin_ip, create_env_cmd) - list_env_cmd = 'fuel2 config env list' + list_env_cmd = 'fuel2 config env list -f json' list_cmd_out = self.ssh_manager.check_call(self.ssh_manager.admin_ip, - list_env_cmd)['stdout_str'] + list_env_cmd).stdout_json self.show_step(3) # Verify environment fields - # TODO(akostrikov) parse stdout of create to find id! - # TODO(akostrikov) bug for name in env to find by uniq name - actual_env = [e for e in json.loads(list_cmd_out) if + actual_env = [e for e in list_cmd_out if e['hierarchy_levels'] == ['servers']][0] assert_equal(actual_env['hierarchy_levels'], ['servers']) assert_equal(actual_env['components'], []) @@ -177,49 +169,49 @@ class TestsConfigDBAPI(TestBasic): list_component_cmd = 'fuel2 config comp list --format json' list_cmd_out = self.ssh_manager.check_call( admin_ip, - list_component_cmd)['stdout_str'] + list_component_cmd).stdout_json - res_comp = [c for c in json.loads(list_cmd_out) if + res_comp = [c for c in list_cmd_out if c['name'] == 'res'][0] assert_equal(res_comp['resource_definitions'], []) res_id = res_comp['id'] self.show_step(5) # Create environment with component - create_with_comp = 'fuel2 config env create -c {id}'.format(id=res_id) + create_with_comp = 'fuel2 config env create -i {id} -f json'.format( + id=res_id) self.ssh_manager.check_call(admin_ip, create_with_comp) self.show_step(6) # Verify environment with component - find_comp_env = 'fuel2 config env list' + find_comp_env = 'fuel2 config env list -f json' env_list = self.ssh_manager.check_call(admin_ip, - find_comp_env)['stdout_str'] - env_comp = [e for e in json.loads(env_list) + find_comp_env).stdout_json + env_comp = [e for e in env_list if e['components'] == [res_id]][0] assert_equal(env_comp['hierarchy_levels'], []) self.show_step(7) # Create environment with component and level - create_lvl_comp = 'fuel2 config env create -c {id} -l nodes'.format( - id=res_id) + create_lvl_comp = 'fuel2 config env create ' \ + '-i {id} -l nodes -f json'.format(id=res_id) out_lvl_comp = self.ssh_manager.check_call( - admin_ip, create_lvl_comp)['stdout_str'] + admin_ip, create_lvl_comp).stdout_json self.show_step(8) # Verify environment with component and level - env_lvl_comp = json.loads(out_lvl_comp) + env_lvl_comp = out_lvl_comp assert_equal(env_lvl_comp['components'], [res_id]) assert_equal(env_lvl_comp['hierarchy_levels'], ['nodes']) self.show_step(9) # Create environment with component and two levels create_new_comp = 'fuel2 config comp create -n another_comp -f json' comp_res = self.ssh_manager.check_call( - admin_ip, create_new_comp)['stdout_str'] - comp_id = json.loads(comp_res)['id'] + admin_ip, create_new_comp).stdout_json + comp_id = comp_res['id'] create_mult_env_cmd = 'fuel2 config env create ' \ - '-l nodes,servers ' \ - '-c{id1},{id2}'.format(id1=comp_id, id2=res_id) - env_res = self.ssh_manager.check_call( - admin_ip, create_mult_env_cmd)['stdout_str'] + '-l nodes,servers -f json ' \ + '-i{id1},{id2}'.format(id1=comp_id, id2=res_id) + env_obj = self.ssh_manager.check_call( + admin_ip, create_mult_env_cmd).stdout_json self.show_step(10) # Verify environment with component and two levels - env_obj = json.loads(env_res) levels = env_obj['hierarchy_levels'] levels_contained = functools.reduce(operator.and_, @@ -238,6 +230,7 @@ class TestsConfigDBAPI(TestBasic): @test(depends_on_groups=['create_component_and_env_configdb'], groups=['configdb_cli_interface']) + @log_snapshot_after_test def resource_value_without_level(self): """Getting and setting resources without level with cli @@ -260,22 +253,21 @@ class TestsConfigDBAPI(TestBasic): self.show_step(2) # Create component with resource for environment create_new_comp = 'fuel2 config comp create -n another_comp -f json' comp_res = self.ssh_manager.check_call( - admin_ip, create_new_comp)['stdout_str'] - comp_id = json.loads(comp_res)['id'] + admin_ip, create_new_comp).stdout_json + comp_id = comp_res['id'] create_res_cmd = 'fuel2 config def create --name res1 -i {id} ' \ '--content \'{{"var": 1}}\' ' \ '-t json -f json'.format(id=comp_id) create_res_out = self.ssh_manager.check_call( - admin_ip, create_res_cmd)['stdout_str'] - create_res_obj = json.loads(create_res_out) + admin_ip, create_res_cmd).stdout_json + create_res_obj = create_res_out res_id = create_res_obj['id'] self.show_step(3) # Create environment with component - create_mult_env_cmd = 'fuel2 config env create ' \ - '-c{cid}'.format(cid=comp_id) - env_res = self.ssh_manager.check_call( - admin_ip, create_mult_env_cmd)['stdout_str'] - env_obj = json.loads(env_res) + create_mult_env_cmd = 'fuel2 config env create -f json ' \ + '-i{cid}'.format(cid=comp_id) + env_obj = self.ssh_manager.check_call( + admin_ip, create_mult_env_cmd).stdout_json env_id = env_obj['id'] self.show_step(4) # Get default resource value @@ -283,9 +275,8 @@ class TestsConfigDBAPI(TestBasic): '--resource {res_id} ' \ '-f json'.format(env_id=env_id, res_id=res_id) admin_ip = self.ssh_manager.admin_ip - res = self.ssh_manager.execute_on_remote( - ip=admin_ip, cmd=get_resource_cmd)['stdout_str'] - res_obj = json.loads(res) + res_obj = self.ssh_manager.check_call( + admin_ip, get_resource_cmd).stdout_json assert_equal(res_obj, {}) self.show_step(5) # Update resource value @@ -294,17 +285,16 @@ class TestsConfigDBAPI(TestBasic): '--key key --type json' set_resource_cmd = set_resource_cmd.format(env_id=env_id, res_id=res_id) - self.ssh_manager.execute_on_remote( - ip=admin_ip, cmd=set_resource_cmd) + self.ssh_manager.check_call( + admin_ip, set_resource_cmd) self.show_step(6) # Verify updated resource value get_resource_cmd = 'fuel2 config get --env {env_id} ' \ '--resource {res_id} ' \ '-f json'.format(env_id=env_id, res_id=res_id) admin_ip = self.ssh_manager.admin_ip - res = self.ssh_manager.execute_on_remote( - ip=admin_ip, cmd=get_resource_cmd)['stdout_str'] - res_obj = json.loads(res) + res_obj = self.ssh_manager.check_call( + admin_ip, get_resource_cmd).stdout_json assert_equal(res_obj['key'], {'a': 1, 'b': None}) self.show_step(7) # Make snapshot @@ -312,6 +302,7 @@ class TestsConfigDBAPI(TestBasic): @test(depends_on_groups=['create_component_and_env_configdb'], groups=['configdb_cli_interface']) + @log_snapshot_after_test def resource_value_with_level(self): """Getting and setting resources without level with cli @@ -335,31 +326,28 @@ class TestsConfigDBAPI(TestBasic): self.show_step(2) # Create component for environment create_new_comp = 'fuel2 config comp create -n another_comp -f json' comp_res = self.ssh_manager.check_call( - admin_ip, create_new_comp)['stdout_str'] - comp_id = json.loads(comp_res)['id'] + admin_ip, create_new_comp).stdout_json + comp_id = comp_res['id'] create_res_cmd = 'fuel2 config def create --name res1 -i {id} ' \ '--content \'{{"var": 1}}\' ' \ '-t json -f json'.format(id=comp_id) - create_res_out = self.ssh_manager.check_call( - admin_ip, create_res_cmd)['stdout_str'] - create_res_obj = json.loads(create_res_out) + create_res_obj = self.ssh_manager.check_call( + admin_ip, create_res_cmd).stdout_json res_id = create_res_obj['id'] self.show_step(3) # Create environment with component and levels create_mult_env_cmd = 'fuel2 config env create -l nodes ' \ - '-c{cid}'.format(cid=comp_id) - env_res = self.ssh_manager.check_call( - admin_ip, create_mult_env_cmd)['stdout_str'] - env_obj = json.loads(env_res) + '-i{cid} -f json'.format(cid=comp_id) + env_obj = self.ssh_manager.check_call( + admin_ip, create_mult_env_cmd).stdout_json env_id = env_obj['id'] get_resource_cmd = 'fuel2 config get --env {env_id} ' \ '--resource {res_id} ' \ '-f json'.format(env_id=env_id, res_id=res_id) admin_ip = self.ssh_manager.admin_ip - res = self.ssh_manager.check_call( + res_obj = self.ssh_manager.check_call( admin_ip, - get_resource_cmd)['stdout_str'] - res_obj = json.loads(res) + get_resource_cmd).stdout_json assert_equal(res_obj, {}) self.show_step(4) # Get default resource value by level @@ -367,9 +355,8 @@ class TestsConfigDBAPI(TestBasic): '--resource {res_id} ' \ '--format json --level nodes=1'.format(env_id=env_id, res_id=res_id) - lvl_res = self.ssh_manager.check_call( - admin_ip, get_lvl_res_cmd)['stdout_str'] - lvl_obj = json.loads(lvl_res) + lvl_obj = self.ssh_manager.check_call( + admin_ip, get_lvl_res_cmd).stdout_json assert_equal(lvl_obj, {}) self.show_step(5) # Update resource value with level @@ -386,9 +373,8 @@ class TestsConfigDBAPI(TestBasic): '--resource {res_id} ' \ '--format json --level nodes=1'.format(env_id=env_id, res_id=res_id) - lvl_res = self.ssh_manager.check_call( - admin_ip, get_lvl_res_cmd)['stdout_str'] - lvl_obj = json.loads(lvl_res) + lvl_obj = self.ssh_manager.check_call( + admin_ip, get_lvl_res_cmd).stdout_json assert_equal(lvl_obj['key']['a'], 1) assert_equal(lvl_obj['key']['b'], None) @@ -397,9 +383,8 @@ class TestsConfigDBAPI(TestBasic): '--resource {res_id} ' \ '--format json'.format(env_id=env_id, res_id=res_id) - lvl_res = self.ssh_manager.check_call( - admin_ip, get_lvl_res_cmd)['stdout_str'] - lvl_obj = json.loads(lvl_res) + lvl_obj = self.ssh_manager.check_call( + admin_ip, get_lvl_res_cmd).stdout_json assert_equal(lvl_obj, {}) self.show_step(8) # Make snapshot @@ -407,6 +392,7 @@ class TestsConfigDBAPI(TestBasic): @test(depends_on_groups=['create_component_and_env_configdb'], groups=['configdb_cli_interface']) + @log_snapshot_after_test def merge_overrides_without_level(self): """Test overrides behaviour without levels @@ -429,31 +415,29 @@ class TestsConfigDBAPI(TestBasic): self.show_step(2) # Create component for environment create_new_comp = 'fuel2 config comp create -n another_comp -f json' comp_res = self.ssh_manager.check_call( - admin_ip, create_new_comp)['stdout_str'] - comp_id = json.loads(comp_res)['id'] + admin_ip, create_new_comp).stdout_json + comp_id = comp_res['id'] create_res_cmd = 'fuel2 config def create --name res1 -i {id} ' \ '--content \'{{"var": 1}}\' ' \ '-t json -f json'.format(id=comp_id) - create_res_out = self.ssh_manager.check_call( - admin_ip, create_res_cmd)['stdout_str'] - create_res_obj = json.loads(create_res_out) + create_res_obj = self.ssh_manager.check_call( + admin_ip, create_res_cmd).stdout_json res_id = create_res_obj['id'] self.show_step(3) # Create environment for overrides create_mult_env_cmd = 'fuel2 config env create ' \ - '-c{cid}'.format(cid=comp_id) - env_res = self.ssh_manager.check_call( - admin_ip, create_mult_env_cmd)['stdout_str'] - env_obj = json.loads(env_res) + '-i{cid} -f json'.format(cid=comp_id) + env_obj = self.ssh_manager.check_call( + admin_ip, create_mult_env_cmd).stdout_json env_id = env_obj['id'] self.show_step(4) # Update resource value - # TODO(akostrikov) operations on resource by resource name + # TODO(akostrikov) Operations on resource by resource name set_res_cmd = 'fuel2 config set --env {env_id} --resource ' \ '{res_id} --value \'{{"a": 1, "b": null}}\' ' \ '--key key --type ' \ - 'json --level nodes=1'.format(env_id=env_id, - res_id=res_id) + 'json'.format(env_id=env_id, + res_id=res_id) self.ssh_manager.check_call( admin_ip, set_res_cmd) @@ -461,8 +445,8 @@ class TestsConfigDBAPI(TestBasic): set_override_cmd = 'fuel2 config override --env {env_id} --resource ' \ '{res_id} --value \'{{"a": 3, "b": null}}\' ' \ '--key key --type ' \ - 'json --level nodes=1'.format(env_id=env_id, - res_id=res_id) + 'json'.format(env_id=env_id, + res_id=res_id) self.ssh_manager.check_call( admin_ip, set_override_cmd) @@ -471,9 +455,8 @@ class TestsConfigDBAPI(TestBasic): '--resource {res_id} ' \ '-f json'.format(env_id=env_id, res_id=res_id) admin_ip = self.ssh_manager.admin_ip - res = self.ssh_manager.check_call( - admin_ip, get_resource_cmd)['stdout_str'] - res_obj = json.loads(res) + res_obj = self.ssh_manager.check_call( + admin_ip, get_resource_cmd).stdout_json assert_equal(res_obj['key']['a'], 3) assert_equal(res_obj['key']['b'], None) @@ -482,6 +465,7 @@ class TestsConfigDBAPI(TestBasic): @test(depends_on_groups=['create_component_and_env_configdb'], groups=['configdb_cli_interface']) + @log_snapshot_after_test def merge_overrides_with_level(self): """Test overrides behaviour with levels @@ -492,7 +476,7 @@ class TestsConfigDBAPI(TestBasic): 4. Update resource value with level 5. Update resource override with level 6. Check effective value with level - 7. Check effective value with level + 7. Check effective value without level 8. Make snapshot Duration: 5 min @@ -505,22 +489,20 @@ class TestsConfigDBAPI(TestBasic): self.show_step(2) # Create component for environment create_new_comp = 'fuel2 config comp create -n another_comp -f json' comp_res = self.ssh_manager.check_call( - admin_ip, create_new_comp)['stdout_str'] - comp_id = json.loads(comp_res)['id'] + admin_ip, create_new_comp).stdout_json + comp_id = comp_res['id'] create_res_cmd = 'fuel2 config def create --name res1 -i {id} ' \ '--content \'{{"var": 1}}\' ' \ '-t json -f json'.format(id=comp_id) - create_res_out = self.ssh_manager.check_call( - admin_ip, create_res_cmd)['stdout_str'] - create_res_obj = json.loads(create_res_out) + create_res_obj = self.ssh_manager.check_call( + admin_ip, create_res_cmd).stdout_json res_id = create_res_obj['id'] self.show_step(3) # Create environment for overrides - create_mult_env_cmd = 'fuel2 config env create ' \ - '-c{cid}'.format(cid=comp_id) - env_res = self.ssh_manager.check_call( - admin_ip, create_mult_env_cmd)['stdout_str'] - env_obj = json.loads(env_res) + create_mult_env_cmd = 'fuel2 config env create -l nodes ' \ + '-i{cid} -f json'.format(cid=comp_id) + env_obj = self.ssh_manager.check_call( + admin_ip, create_mult_env_cmd).stdout_json env_id = env_obj['id'] self.show_step(4) # Update resource value with level @@ -545,9 +527,8 @@ class TestsConfigDBAPI(TestBasic): get_resource_cmd = 'fuel2 config get --env {env_id} ' \ '--resource {res_id} --level nodes=1 ' \ '-f json'.format(env_id=env_id, res_id=res_id) - res = self.ssh_manager.check_call( - admin_ip, get_resource_cmd)['stdout_str'] - res_obj = json.loads(res) + res_obj = self.ssh_manager.check_call( + admin_ip, get_resource_cmd).stdout_json assert_equal(res_obj['key']['a'], 3) assert_equal(res_obj['key']['b'], None) @@ -556,20 +537,18 @@ class TestsConfigDBAPI(TestBasic): '--resource {res_id} ' \ '-f json'.format(env_id=env_id, res_id=res_id) - res = self.ssh_manager.check_call( - admin_ip, get_resource_cmd)['stdout_str'] - res_obj = json.loads(res) - # TODO(akostrikov) https://bugs.launchpad.net/fuel/+bug/1619264 + res_obj = self.ssh_manager.check_call( + admin_ip, get_resource_cmd).stdout_json assert_equal(res_obj, {}) - # TODO(akostrikov) multiple levels + # TODO(akostrikov) Multiple levels self.show_step(8) # Make snapshot self.env.make_snapshot('configdb_resource_tests_lvl_overrides') @test(depends_on_groups=['create_component_and_env_configdb'], groups=['configdb_cli_interface']) def update_via_key_path(self): - # TODO(akostrikov) Update_key_by_path + # TODO(akostrikov) Update key by path pass @test(depends_on_groups=['create_component_and_env_configdb'],