Best Python code snippet using tempest_python
test_congress_basic_ops.py
Source:test_congress_basic_ops.py
...90 action_args = {'args': {'positional': [],91 'named': {'server': server['id'],92 'metadata': metadata}}}93 body = action_args94 f = lambda: servers_client.show_server_metadata_item(server['id'],95 'testkey1')96 # execute via datasource api97 body.update({'name': action})98 congress_client.execute_datasource_action(service, "execute", body)99 helper.retry_check_function_return_value(f, res)100 # execute via policy api101 body.update({'name': service + ':' + action})102 congress_client.execute_policy_action(policy, "execute", False,103 False, body)104 helper.retry_check_function_return_value(f, res)105 @test.attr(type='smoke')106 @test.services('compute', 'network')107 def test_policy_basic_op(self):108 self._setup_network_and_servers()109 body = {"rule": "port_security_group(id, security_group_name) "110 ":-neutronv2:ports(id, tenant_id, name, network_id,"111 "mac_address, admin_state_up, status, device_id, "112 "device_owner),"113 "neutronv2:security_group_port_bindings(id, "114 "security_group_id), neutronv2:security_groups("115 "security_group_id, tenant_id1, security_group_name,"116 "description)"}117 results = self.admin_manager.congress_client.create_policy_rule(118 'classification', body)119 rule_id = results['id']120 self.addCleanup(121 self.admin_manager.congress_client.delete_policy_rule,122 'classification', rule_id)123 # Find the ports of on this server124 ports = self._list_ports(device_id=self.servers[0]['id'])125 def check_data():126 results = self.admin_manager.congress_client.list_policy_rows(127 'classification', 'port_security_group')128 for row in results['results']:129 if (row['data'][0] == ports[0]['id'] and130 row['data'][1] ==131 self.servers[0]['security_groups'][0]['name']):132 return True133 else:134 return False135 time.sleep(65) # sleep for replicated PE sync136 # Note(ekcs): do not use retry because we want to make sure the call137 # succeeds on the first try after adequate time.138 # If retry used, it may pass based on succeding on one replica but139 # failing on all others.140 self.assertTrue(check_data(),141 "Data did not converge in time or failure in server")142 @test.attr(type='smoke')143 @test.services('compute', 'network')144 def test_reactive_enforcement(self):145 servers_client = self.admin_manager.servers_client146 server_name = 'server_under_test'147 server = self._create_test_server(name=server_name)148 policy_name = self._create_random_policy()149 meta_key = 'meta_test_key1'150 meta_val = 'value1'151 meta_data = {'meta': {meta_key: meta_val}}152 rules = [153 'execute[nova:servers_set_meta(id, "%s", "%s")] :- '154 'test_servers(id)' % (meta_key, meta_val),155 'test_servers(id) :- '156 'nova:servers(id, name, host_id, status, tenant_id,'157 'user_id, image_id, flavor_id, zone, host_name),'158 'equal(name, "%s")' % server_name]159 for rule in rules:160 self._create_policy_rule(policy_name, rule)161 f = lambda: servers_client.show_server_metadata_item(server['id'],162 meta_key)163 time.sleep(80) # sleep for replicated PE sync164 # Note: seems reactive enforcement takes a bit longer165 # succeeds on the first try after adequate time.166 # If retry used, it may pass based on succeding on one replica but167 # failing on all others.168 self.assertEqual(f(), meta_data)169class TestCongressDataSources(manager_congress.ScenarioPolicyBase):170 @classmethod171 def skip_checks(cls):172 super(TestCongressDataSources, cls).skip_checks()173 if not (CONF.network.project_networks_reachable174 or CONF.network.public_network_id):175 msg = ('Either project_networks_reachable must be "true", or '...
test_server_metadata_rbac.py
Source:test_server_metadata_rbac.py
...53 @decorators.idempotent_id('93dd8323-d3fa-48d1-8bd6-91c1b62fc341')54 @rbac_rule_validation.action(55 service="nova",56 rules=["os_compute_api:server-metadata:show"])57 def test_show_server_metadata_item(self):58 with self.override_role():59 self.servers_client.show_server_metadata_item(60 self.server['id'], 'default_key')61 @decorators.idempotent_id('79511293-4bd7-447d-ba7e-634d0f4da70c')62 @rbac_rule_validation.action(63 service="nova",64 rules=["os_compute_api:server-metadata:update"])65 def test_set_server_metadata_item(self):66 with self.override_role():67 self.servers_client.set_server_metadata_item(68 self.server['id'], 'default_key', {'default_key': 'value2'})69 @decorators.idempotent_id('feec5064-678d-40bc-a88f-c856e18d1e31')70 @rbac_rule_validation.action(71 service="nova",72 rules=["os_compute_api:server-metadata:delete"])73 def test_delete_server_metadata_item(self):...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!