class KeystoneBasic(kutils.KeystoneScenario): @base.scenario(admin_only=True, context={"cleanup": []}) def create_user(self, name_length=10, **kwargs): self._user_create(name_length=name_length, **kwargs) @base.scenario(admin_only=True, context={"cleanup": []}) def create_delete_user(self, name_length=10, **kwargs): user = self._user_create(name_length=name_length, **kwargs) self._resource_delete(user) @base.scenario(admin_only=True, context={"cleanup": []}) def create_tenant(self, name_length=10, **kwargs): self._tenant_create(name_length=name_length, **kwargs) @base.scenario(admin_only=True, context={"cleanup": []}) @valid.add_validator(valid.required_parameters(['users_per_tenant'])) def create_tenant_with_users(self, users_per_tenant, name_length=10, **kwargs): tenant = self._tenant_create(name_length=name_length, **kwargs) self._users_create(tenant, users_per_tenant=users_per_tenant, name_length=name_length) @base.scenario(admin_only=True, context={"cleanup": []}) def create_and_list_users(self, name_length=10, **kwargs): self._user_create(name_length=name_length, **kwargs) self._list_users() @base.scenario(admin_only=True, context={"cleanup": []}) def create_and_list_tenants(self, name_length=10, **kwargs): self._tenant_create(name_length=name_length, **kwargs) self._list_tenants()
class NeutronNetworks(utils.NeutronScenario): @base.scenario(context={"cleanup": ["neutron"]}) @validation.required_services(consts.Service.NEUTRON) def create_and_list_networks(self, network_create_args=None): """Create a network and then listing all networks. This scenario is a very useful tool to measure the "neutron net-list" command performance. If you have only 1 user in your context, you will add 1 network on every iteration. So you will have more and more networks and will be able to measure the performance of the "neutron net-list" command depending on the number of networks owned by users. :param network_create_args: dict, POST /v2.0/networks request options """ self._create_network(network_create_args or {}) self._list_networks() @base.scenario(context={"cleanup": ["neutron"]}) def create_and_update_networks(self, network_update_args, network_create_args=None): """Create a network and then update network. This scenario is a very useful tool to measure the "neutron net-update" command performance. If you have only 1 user in your context, you will add 1 network on every iteration. So you will have more and more networks and will be able to measure the performance of the "neutron net-update" command depending on the number of networks owned by users. :param network_create_args: dict, POST /v2.0/networks request options """ network = self._create_network(network_create_args or {}) body = { 'network' : { 'name' : network['network']['name']+network_update_args['name'] }} self._update_network(network['network']['id'], body) @base.scenario(context={"cleanup": ["neutron"]}) @validation.required_services(consts.Service.NEUTRON) def create_and_delete_networks(self, network_create_args=None): """Create a network and then delete network. This scenario is a very useful tool to measure the "neutron net-delete" command performance. If you have only 1 user in your context, you will add 1 network on every iteration. So you will have more and more networks and will be able to measure the performance of the "neutron net-delete" command depending on the number of networks owned by users. :param network_create_args: dict, POST /v2.0/networks request options """ network = self._create_network(network_create_args or {}) self._delete_network(network['network']['id']) @base.scenario(context={"cleanup": ["neutron"]}) @validation.add(validation.required_parameters(['subnets_per_network'])) @validation.required_services(consts.Service.NEUTRON) def create_and_list_subnets(self, network_create_args=None, subnet_create_args=None, subnet_cidr_start=None, subnets_per_network=None): """Test creating and listing a given number of subnets. The scenario creates a network, a given number of subnets and then lists subnets. :param network_create_args: dict, POST /v2.0/networks request options :param subnet_create_args: dict, POST /v2.0/subnets request options :param subnet_cidr_start: str, start value for subnets CIDR :param subnets_per_network: int, number of subnets for one network """ if subnet_cidr_start: NeutronNetworks.SUBNET_CIDR_START = subnet_cidr_start network = self._create_network(network_create_args or {}) for i in range(subnets_per_network): self._create_subnet(network, subnet_create_args or {}) #self._list_subnets() @base.scenario(context={"cleanup": ["neutron"]}) @validation.add(validation.required_parameters(['subnets_per_network'])) def create_and_update_subnets(self, subnet_update_args, network_create_args=None, subnet_create_args=None, subnet_cidr_start=None, subnets_per_network=None): """Create a subnet and then update subnet. This scenario is a very useful tool to measure the "neutron subnet-update" command performance. :param network_create_args: dict, POST /v2.0/networks request options :param subnet_create_args: dict, POST /v2.0/subnets request options :param subnet_cidr_start: str, start value for subnets CIDR :param subnets_per_network: int, number of subnets for one network """ network = self._create_network(network_create_args or {}) for i in range(subnets_per_network): subnet = self._create_subnet(network, subnet_create_args or {}) body = { 'subnet' : { 'name' : subnet['subnet']['name']+subnet_update_args['name'] }} self._update_subnet(subnet['subnet']['id'], body) self._list_subnets() @base.scenario(context={"cleanup": ["neutron"]}) @validation.add(validation.required_parameters(['subnets_per_network'])) def create_and_delete_subnets(self, network_create_args=None, subnet_create_args=None, subnet_cidr_start=None, subnets_per_network=None): """Test creating and deleting a given number of subnets. The scenario creates a network, a given number of subnets and then deletes subnets. :param network_create_args: dict, POST /v2.0/networks request options :param subnet_create_args: dict, POST /v2.0/subnets request options :param subnet_cidr_start: str, start value for subnets CIDR :param subnets_per_network: int, number of subnets for one network """ if subnet_cidr_start: NeutronNetworks.SUBNET_CIDR_START = subnet_cidr_start network = self._create_network(network_create_args or {}) for i in range(subnets_per_network): subnet = self._create_subnet(network, subnet_create_args or {}) self._delete_subnet(subnet["subnet"]["id"]) self._delete_network(network['network']['id']) @base.scenario(context={"cleanup": ["neutron"]}) @validation.add(validation.required_parameters(['subnets_per_network'])) @validation.required_services(consts.Service.NEUTRON) def create_and_list_routers(self, network_create_args=None, subnet_create_args=None, subnet_cidr_start=None, subnets_per_network=None, router_create_args=None): """Test creating and listing a given number of routers. Create a network, a given number of subnets and routers and then list all routers. :param network_create_args: dict, POST /v2.0/networks request options :param subnet_create_args: dict, POST /v2.0/subnets request options :param subnet_cidr_start: str, start value for subnets CIDR :param subnets_per_network: int, number of subnets for one network :param router_create_args: dict, POST /v2.0/routers request options """ if subnet_cidr_start: NeutronNetworks.SUBNET_CIDR_START = subnet_cidr_start network = self._create_network(network_create_args or {}) for i in range(subnets_per_network): subnet = self._create_subnet(network, subnet_create_args or {}) router = self._create_router(router_create_args or {}) self.clients("neutron").add_interface_router( router["router"]["id"], {"subnet_id": subnet["subnet"]["id"]}) self._list_routers() @base.scenario(context={"cleanup": ["neutron"]}) @validation.add(validation.required_parameters(['subnets_per_network'])) def create_and_update_routers(self, router_update_args, network_create_args=None, subnet_create_args=None, subnet_cidr_start=None, subnets_per_network=None, router_create_args=None): """Test creating and updating a given number of routers. Create a network, a given number of subnets and routers and then updating all routers. :param network_create_args: dict, POST /v2.0/networks request options :param subnet_create_args: dict, POST /v2.0/subnets request options :param subnet_cidr_start: str, start value for subnets CIDR :param subnets_per_network: int, number of subnets for one network :param router_create_args: dict, POST /v2.0/routers request options """ if subnet_cidr_start: NeutronNetworks.SUBNET_CIDR_START = subnet_cidr_start network = self._create_network(network_create_args or {}) for i in range(subnets_per_network): subnet = self._create_subnet(network, subnet_create_args or {}) router = self._create_router(router_create_args or {}) self.clients("neutron").add_interface_router( router["router"]["id"], {"subnet_id": subnet["subnet"]["id"]}) body = { 'router' : { 'name' : router['router']['name']+router_update_args['name'] , 'admin_state_up' : router_update_args['admin_state_up']}} router1=self._update_router(router['router']['id'],body) @base.scenario(context={"cleanup": ["neutron"]}) @validation.add(validation.required_parameters(['subnets_per_network'])) def create_and_delete_routers(self, network_create_args=None, subnet_create_args=None, subnet_cidr_start=None, subnets_per_network=None, router_create_args=None): """Test creating and deleting a given number of routers. Create a network, a given number of subnets and routers and then delete all routers, :param network_create_args: dict, POST /v2.0/networks request options :param subnet_create_args: dict, POST /v2.0/subnets request options :param subnet_cidr_start: str, start value for subnets CIDR :param subnets_per_network: int, number of subnets for one network :param router_create_args: dict, POST /v2.0/routers request options """ if subnet_cidr_start: NeutronNetworks.SUBNET_CIDR_START = subnet_cidr_start network = self._create_network(network_create_args or {}) for i in range(subnets_per_network): subnet = self._create_subnet(network, subnet_create_args or {}) router = self._create_router(router_create_args or {}) self.clients("neutron").add_interface_router( router["router"]["id"], {"subnet_id": subnet["subnet"]["id"]}) self.clients("neutron").remove_interface_router( router["router"]["id"], {"subnet_id": subnet["subnet"]["id"]}) self._delete_router(router["router"]["id"]) self._delete_subnet(subnet["subnet"]["id"]) self._delete_network(network['network']['id']) @base.scenario(context={"cleanup": ["neutron"]}) @validation.add(validation.required_parameters(["ports_per_network"])) @validation.required_services(consts.Service.NEUTRON) def create_and_list_ports(self, network_create_args=None, subnet_create_args=None, subnet_cidr_start=None, subnets_per_network=None, port_create_args=None, ports_per_network=None): """Test creating and listing a given number of ports. :param network_create_args: dict, POST /v2.0/networks request options :param port_create_args: dict, POST /v2.0/ports request options :param ports_per_network: int, number of ports for one network """ #network = self._create_network(network_create_args or {}) if subnet_cidr_start: NeutronNetworks.SUBNET_CIDR_START = subnet_cidr_start network = self._create_network(network_create_args or {}) for i in range(subnets_per_network): self._create_subnet(network, subnet_create_args or {}) # for i in range(ports_per_network): # self._create_port(network, port_create_args or {}) #self._list_ports() self._list_subnets() @base.scenario(context={"cleanup": ["neutron"]}) @validation.add(validation.required_parameters(["ports_per_network"])) def create_update_and_list_ports(self, port_update_args, network_create_args=None, subnet_create_args=None, subnet_cidr_start=None, subnets_per_network=None, port_create_args=None, ports_per_network=None): """Test creating and listing a given number of ports. :param network_create_args: dict, POST /v2.0/networks request options :param port_create_args: dict, POST /v2.0/ports request options :param ports_per_network: int, number of ports for one network """ #network = self._create_network(network_create_args or {}) if subnet_cidr_start: NeutronNetworks.SUBNET_CIDR_START = subnet_cidr_start network = self._create_network(network_create_args or {}) for i in range(subnets_per_network): self._create_subnet(network, subnet_create_args or {}) for i in range(ports_per_network): port = self._create_port(network, port_create_args or {}) body = { 'port' : { 'name' : port['port']['name']+port_update_args['name'] , 'admin_state_up' : port_update_args['admin_state_up']}} self._update_port(port['port']['id'],body) self._list_ports() @base.scenario(context={"cleanup": ["neutron"]}) @validation.add(validation.required_parameters(["ports_per_network"])) def create_and_delete_ports(self, network_create_args=None, subnet_create_args=None, subnet_cidr_start=None, subnets_per_network=None, port_create_args=None, ports_per_network=None): """Test creating and deleting a given number of ports. :param network_create_args: dict, POST /v2.0/networks request options :param port_create_args: dict, POST /v2.0/ports request options :param ports_per_network: int, number of ports for one network """ #network = self._create_network(network_create_args or {}) if subnet_cidr_start: NeutronNetworks.SUBNET_CIDR_START = subnet_cidr_start network = self._create_network(network_create_args or {}) for i in range(subnets_per_network): self._create_subnet(network, subnet_create_args or {}) for i in range(ports_per_network): port = self._create_port(network, port_create_args or {}) self._delete_port(port['port']['id']) """for i in range(ports_per_network):
def test_required_parameters(self): validator = validation.required_parameters("test1") config = {"args": {}} result = validator(config, clients=None, task=mock.MagicMock()) self.assertFalse(result.is_valid)
class Authenticate(base.Scenario): """This class should contain authentication mechanism. For different types of clients like Keystone. """ @base.scenario() @base.atomic_action_timer('authenticate.keystone') def keystone(self, **kwargs): self.clients("keystone") @base.scenario() @validation.add(validation.required_parameters(['repetitions'])) def validate_glance(self, repetitions): """Check Glance Client to ensure validation of token. Creation of the client does not ensure validation of the token. We have to do some minimal operation to make sure token gets validated. In following we are checking for non-existent image. :param repetitions: number of times to validate """ glance_client = self.clients("glance") image_name = "__intentionally_non_existent_image___" for i in range(repetitions): with base.AtomicAction(self, 'authenticate.validate_glance'): list(glance_client.images.list(name=image_name)) @base.scenario() @validation.add(validation.required_parameters(['repetitions'])) def validate_nova(self, repetitions): """Check Nova Client to ensure validation of token. Creation of the client does not ensure validation of the token. We have to do some minimal operation to make sure token gets validated. :param repetitions: number of times to validate """ nova_client = self.clients("nova") for i in range(repetitions): with base.AtomicAction(self, 'authenticate.validate_nova'): nova_client.flavors.list() @base.scenario() @validation.add(validation.required_parameters(['repetitions'])) def validate_cinder(self, repetitions): """Check Cinder Client to ensure validation of token. Creation of the client does not ensure validation of the token. We have to do some minimal operation to make sure token gets validated. :param repetitions: number of times to validate """ cinder_client = self.clients("cinder") for i in range(repetitions): with base.AtomicAction(self, 'authenticate.validate_cinder'): cinder_client.volume_types.list() @base.scenario() @validation.add(validation.required_parameters(['repetitions'])) def validate_neutron(self, repetitions): """Check Neutron Client to ensure validation of token. Creation of the client does not ensure validation of the token. We have to do some minimal operation to make sure token gets validated. :param repetitions: number of times to validate """ neutron_client = self.clients("neutron") for i in range(repetitions): with base.AtomicAction(self, 'authenticate.validate_neutron'): neutron_client.get_auth_info() @base.scenario() @validation.add(validation.required_parameters(['repetitions'])) def validate_heat(self, repetitions): """Check Heat Client to ensure validation of token. Creation of the client does not ensure validation of the token. We have to do some minimal operation to make sure token gets validated. :param repetitions: number of times to validate """ heat_client = self.clients("heat") for i in range(repetitions): with base.AtomicAction(self, 'authenticate.validate_heat'): list(heat_client.stacks.list(limit=0))
def test_required_parameters(self): validator = validation.required_parameters("test1") result = validator(task=mock.MagicMock()) self.assertFalse(result.is_valid)
def test_required_parameters(self): validator = validation.required_parameters("test1") config = {"args": {}} result = validator(config, clients=None, task=mock.MagicMock()) self.assertFalse(result.is_valid)