def _test_create_resource(self, resource, cmd, name, myid, args, position_names, position_values, tenant_id=None, tags=None, admin_state_up=True, extra_body=None, **kwargs): self.mox.StubOutWithMock(cmd, "get_client") self.mox.StubOutWithMock(self.client.httpclient, "request") cmd.get_client().MultipleTimes().AndReturn(self.client) non_admin_status_resources = ['subnet', 'floatingip', 'security_group', 'security_group_rule', 'qos_queue', 'network_gateway', 'gateway_device', 'credential', 'network_profile', 'policy_profile', 'ikepolicy', 'ipsecpolicy', 'metering_label', 'metering_label_rule', 'net_partition'] if (resource in non_admin_status_resources): body = {resource: {}, } else: body = {resource: {'admin_state_up': admin_state_up, }, } if tenant_id: body[resource].update({'tenant_id': tenant_id}) if tags: body[resource].update({'tags': tags}) if extra_body: body[resource].update(extra_body) body[resource].update(kwargs) for i in range(len(position_names)): body[resource].update({position_names[i]: position_values[i]}) ress = {resource: {self.id_field: myid}, } if name: ress[resource].update({'name': name}) self.client.format = self.format resstr = self.client.serialize(ress) # url method body resource_plural = neutronV2_0._get_resource_plural(resource, self.client) path = getattr(self.client, resource_plural + "_path") # Work around for LP #1217791. XML deserializer called from # MyComparator does not decodes XML string correctly. if self.format == 'json': mox_body = MyComparator(body, self.client) else: mox_body = self.client.serialize(body) self.client.httpclient.request( end_url(path, format=self.format), 'POST', body=mox_body, headers=mox.ContainsKeyValue( 'X-Auth-Token', TOKEN)).AndReturn((MyResp(200), resstr)) args.extend(['--request-format', self.format]) self.mox.ReplayAll() cmd_parser = cmd.get_parser('create_' + resource) shell.run_command(cmd, cmd_parser, args) self.mox.VerifyAll() self.mox.UnsetStubs() _str = self.fake_stdout.make_string() self.assertIn(myid, _str) if name: self.assertIn(name, _str)
def _test_create_resource(self, resource, cmd, name, myid, args, position_names, position_values, tenant_id=None, tags=None, admin_state_up=True, extra_body=None, cmd_resource=None, parent_id=None, no_api_call=False, expected_exception=None, **kwargs): self.mox.StubOutWithMock(cmd, "get_client") self.mox.StubOutWithMock(self.client.httpclient, "request") cmd.get_client().MultipleTimes().AndReturn(self.client) if not cmd_resource: cmd_resource = resource if (resource in self.non_admin_status_resources): body = {resource: {}, } else: body = {resource: {'admin_state_up': admin_state_up, }, } if tenant_id: body[resource].update({'tenant_id': tenant_id}) if tags: body[resource].update({'tags': tags}) if extra_body: body[resource].update(extra_body) body[resource].update(kwargs) for i in range(len(position_names)): body[resource].update({position_names[i]: position_values[i]}) ress = {resource: {self.id_field: myid}, } if name: ress[resource].update({'name': name}) resstr = self.client.serialize(ress) # url method body resource_plural = neutronV2_0._get_resource_plural(cmd_resource, self.client) path = getattr(self.client, resource_plural + "_path") if parent_id: path = path % parent_id mox_body = MyComparator(body, self.client) if not no_api_call: self.client.httpclient.request( end_url(path, format=self.format), 'POST', body=mox_body, headers=mox.ContainsKeyValue( 'X-Auth-Token', TOKEN)).AndReturn((MyResp(200), resstr)) self.mox.ReplayAll() cmd_parser = cmd.get_parser('create_' + resource) if expected_exception: self.assertRaises(expected_exception, shell.run_command, cmd, cmd_parser, args) else: shell.run_command(cmd, cmd_parser, args) _str = self.fake_stdout.make_string() self.assertIn(myid, _str) if name: self.assertIn(name, _str) self.mox.VerifyAll() self.mox.UnsetStubs()
def _test_create_resource(self, resource, cmd, name, myid, args, position_names, position_values, tenant_id=None, tags=None, admin_state_up=True, extra_body=None, cmd_resource=None, parent_id=None, no_api_call=False, expected_exception=None, **kwargs): self.mox.StubOutWithMock(cmd, "get_client") self.mox.StubOutWithMock(self.client.httpclient, "request") cmd.get_client().MultipleTimes().AndReturn(self.client) if not cmd_resource: cmd_resource = resource if (resource in self.non_admin_status_resources): body = {resource: {}, } else: body = {resource: {'admin_state_up': admin_state_up, }, } if tenant_id: body[resource].update({'tenant_id': tenant_id}) if tags: body[resource].update({'tags': tags}) if extra_body: body[resource].update(extra_body) body[resource].update(kwargs) for i in range(len(position_names)): body[resource].update({position_names[i]: position_values[i]}) ress = {resource: {self.id_field: myid}, } if name: ress[resource].update({'name': name}) resstr = self.client.serialize(ress) # url method body resource_plural = neutronV2_0._get_resource_plural(cmd_resource, self.client) path = getattr(self.client, resource_plural + "_path") if parent_id: path = path % parent_id mox_body = MyComparator(body, self.client) if not no_api_call: self.client.httpclient.request( end_url(path, format=self.format), 'POST', body=mox_body, headers=mox.ContainsKeyValue( 'X-Auth-Token', TOKEN)).AndReturn((MyResp(200), resstr)) self.mox.ReplayAll() cmd_parser = cmd.get_parser('create_' + resource) if expected_exception: self.assertRaises(expected_exception, shell.run_command, cmd, cmd_parser, args) else: shell.run_command(cmd, cmd_parser, args) _str = self.fake_stdout.make_string() self.assertIn(myid, _str) if name: self.assertIn(name, _str) self.mox.VerifyAll() self.mox.UnsetStubs()
def _test_create_resource(self, resource, cmd, name, myid, args, position_names, position_values, tenant_id=None, tags=None, admin_state_up=True, extra_body=None, cmd_resource=None, parent_id=None, **kwargs): self.mox.StubOutWithMock(cmd, "get_client") self.mox.StubOutWithMock(self.client.httpclient, "request") cmd.get_client().MultipleTimes().AndReturn(self.client) if not cmd_resource: cmd_resource = resource body = {resource: {}, } body[resource].update(kwargs) for i in range(len(position_names)): body[resource].update({position_names[i]: position_values[i]}) ress = {resource: {self.id_field: myid}, } if name: ress[resource].update({'name': name}) self.client.format = self.format resstr = self.client.serialize(ress) # url method body resource_plural = l2gatewayV2_0._get_resource_plural(cmd_resource, self.client) path = getattr(self.client, resource_plural + "_path") if self.format == 'json': mox_body = MyComparator(body, self.client) else: mox_body = self.client.serialize(body) self.client.httpclient.request( end_url(path, format=self.format), 'POST', body=mox_body, headers=mox.ContainsKeyValue( 'X-Auth-Token', TOKEN)).AndReturn((MyResp(200), resstr)) args.extend(['--request-format', self.format]) self.mox.ReplayAll() cmd_parser = cmd.get_parser('create_' + resource) neutronshell.run_command(cmd, cmd_parser, args) self.mox.VerifyAll() self.mox.UnsetStubs() _str = self.fake_stdout.make_string() self.assertIn(myid, _str) if name: self.assertIn(name, _str)
def _test_create_resource(self, resource, cmd, name, myid, args, position_names, position_values, tenant_id=None, tags=None, admin_state_up=True, extra_body=None, cmd_resource=None, parent_id=None, **kwargs): self.mox.StubOutWithMock(cmd, "get_client") self.mox.StubOutWithMock(self.client.httpclient, "request") cmd.get_client().MultipleTimes().AndReturn(self.client) if not cmd_resource: cmd_resource = resource body = {resource: {}, } body[resource].update(kwargs) for i in range(len(position_names)): body[resource].update({position_names[i]: position_values[i]}) ress = {resource: {self.id_field: myid}, } if name: ress[resource].update({'name': name}) self.client.format = self.format resstr = self.client.serialize(ress) # url method body resource_plural = ovsvappV2_0._get_resource_plural(cmd_resource, self.client) path = getattr(self.client, resource_plural + "_path") if self.format == 'json': mox_body = MyComparator(body, self.client) else: mox_body = self.client.serialize(body) self.client.httpclient.request( end_url(path, format=self.format), 'POST', body=mox_body, headers=mox.ContainsKeyValue( 'X-Auth-Token', TOKEN)).AndReturn((MyResp(200), resstr)) args.extend(['--request-format', self.format]) self.mox.ReplayAll() cmd_parser = cmd.get_parser('create_' + resource) neutronshell.run_command(cmd, cmd_parser, args) self.mox.VerifyAll() self.mox.UnsetStubs() _str = self.fake_stdout.make_string() self.assertIn(myid, _str) if name: self.assertIn(name, _str)
def _test_create_resource( self, resource, cmd, name, myid, args, position_names, position_values, tenant_id=None, tags=None, admin_state_up=True, extra_body=None, cmd_resource=None, parent_id=None, no_api_call=False, expected_exception=None, **kwargs ): self.mox.StubOutWithMock(cmd, "get_client") self.mox.StubOutWithMock(self.client.httpclient, "request") cmd.get_client().MultipleTimes().AndReturn(self.client) if not cmd_resource: cmd_resource = resource if resource in self.non_admin_status_resources: body = {resource: {}} else: body = {resource: {"admin_state_up": admin_state_up}} if tenant_id: body[resource].update({"tenant_id": tenant_id}) if tags: body[resource].update({"tags": tags}) if extra_body: body[resource].update(extra_body) body[resource].update(kwargs) for i in range(len(position_names)): body[resource].update({position_names[i]: position_values[i]}) ress = {resource: {self.id_field: myid}} if name: ress[resource].update({"name": name}) self.client.format = self.format resstr = self.client.serialize(ress) # url method body resource_plural = neutronV2_0._get_resource_plural(cmd_resource, self.client) path = getattr(self.client, resource_plural + "_path") if parent_id: path = path % parent_id # Work around for LP #1217791. XML deserializer called from # MyComparator does not decodes XML string correctly. if self.format == "json": mox_body = MyComparator(body, self.client) else: mox_body = self.client.serialize(body) if not no_api_call: self.client.httpclient.request( end_url(path, format=self.format), "POST", body=mox_body, headers=mox.ContainsKeyValue("X-Auth-Token", TOKEN), ).AndReturn((MyResp(200), resstr)) args.extend(["--request-format", self.format]) self.mox.ReplayAll() cmd_parser = cmd.get_parser("create_" + resource) if expected_exception: self.assertRaises(expected_exception, shell.run_command, cmd, cmd_parser, args) else: shell.run_command(cmd, cmd_parser, args) _str = self.fake_stdout.make_string() self.assertIn(myid, _str) if name: self.assertIn(name, _str) self.mox.VerifyAll() self.mox.UnsetStubs()
def _convert_resource_args(client, parsed_args): resource_type = neutronv20._get_resource_plural( parsed_args.resource_type, client) resource_id = neutronv20.find_resourceid_by_name_or_id( client, parsed_args.resource_type, parsed_args.resource) return resource_type, resource_id
def _make_tags_path(self, resource, resource_id): path = getattr(self.client, "tags_path") resource_plural = neutronV2_0._get_resource_plural( resource, self.client) return path % (resource_plural, resource_id)
def _convert_resource_args(client, parsed_args): resource_type = neutronv20._get_resource_plural(parsed_args.resource_type, client) resource_id = neutronv20.find_resourceid_by_name_or_id( client, parsed_args.resource_type, parsed_args.resource) return resource_type, resource_id