Exemplo n.º 1
0
    def run(self):
        """
        Excecute VPingSSH testcase.

        Sets up the OpenStack keypair, router, security group, and VM instance
        objects then validates the ping.
        :return: the exit code from the super.execute() method
        """
        try:
            super(VPingSSH, self).run()

            log = "Creating keypair with name: '%s'" % self.kp_name
            self.logger.info(log)
            kp_creator = deploy_utils.create_keypair(
                self.os_creds,
                KeypairSettings(name=self.kp_name,
                                private_filepath=self.kp_priv_file,
                                public_filepath=self.kp_pub_file))
            self.creators.append(kp_creator)

            # Creating router to external network
            log = "Creating router with name: '%s'" % self.router_name
            self.logger.info(log)
            net_set = self.network_creator.network_settings
            sub_set = [net_set.subnet_settings[0].name]
            ext_net_name = snaps_utils.get_ext_net_name(self.os_creds)
            router_creator = deploy_utils.create_router(
                self.os_creds,
                RouterSettings(
                    name=self.router_name,
                    external_gateway=ext_net_name,
                    internal_subnets=sub_set))
            self.creators.append(router_creator)

            # Creating Instance 1
            port1_settings = PortSettings(
                name=self.vm1_name + '-vPingPort',
                network_name=self.network_creator.network_settings.name)
            instance1_settings = VmInstanceSettings(
                name=self.vm1_name, flavor=self.flavor_name,
                vm_boot_timeout=self.vm_boot_timeout,
                vm_delete_timeout=self.vm_delete_timeout,
                ssh_connect_timeout=self.vm_ssh_connect_timeout,
                port_settings=[port1_settings])

            log = ("Creating VM 1 instance with name: '%s'"
                   % instance1_settings.name)
            self.logger.info(log)
            self.vm1_creator = deploy_utils.create_vm_instance(
                self.os_creds,
                instance1_settings,
                self.image_creator.image_settings,
                keypair_creator=kp_creator)
            self.creators.append(self.vm1_creator)

            # Creating Instance 2
            sg_creator = self.__create_security_group()
            self.creators.append(sg_creator)

            port2_settings = PortSettings(
                name=self.vm2_name + '-vPingPort',
                network_name=self.network_creator.network_settings.name)
            instance2_settings = VmInstanceSettings(
                name=self.vm2_name, flavor=self.flavor_name,
                vm_boot_timeout=self.vm_boot_timeout,
                vm_delete_timeout=self.vm_delete_timeout,
                ssh_connect_timeout=self.vm_ssh_connect_timeout,
                port_settings=[port2_settings],
                security_group_names=[sg_creator.sec_grp_settings.name],
                floating_ip_settings=[FloatingIpSettings(
                    name=self.vm2_name + '-FIPName',
                    port_name=port2_settings.name,
                    router_name=router_creator.router_settings.name)])

            log = ("Creating VM 2 instance with name: '%s'"
                   % instance2_settings.name)
            self.logger.info(log)
            self.vm2_creator = deploy_utils.create_vm_instance(
                self.os_creds,
                instance2_settings,
                self.image_creator.image_settings,
                keypair_creator=kp_creator)
            self.creators.append(self.vm2_creator)

            return self._execute()
        except Exception as exc:  # pylint: disable=broad-except
            self.logger.error('Unexpected error running test - ' + exc.message)
            return TestCase.EX_RUN_ERROR
        finally:
            self._cleanup()
Exemplo n.º 2
0
    def _prepare_env(self):
        """Create resources needed by test scenarios."""
        LOGGER.debug('Validating the test name...')
        if self.test_name not in self.TESTS:
            raise Exception("Test name '%s' is invalid" % self.test_name)

        network_name = self.RALLY_PRIVATE_NET_NAME + self.guid
        subnet_name = self.RALLY_PRIVATE_SUBNET_NAME + self.guid
        router_name = self.RALLY_ROUTER_NAME + self.guid
        self.image_name = self.GLANCE_IMAGE_NAME + self.guid
        self.flavor_name = self.FLAVOR_NAME + self.guid
        self.flavor_alt_name = self.FLAVOR_ALT_NAME + self.guid
        self.ext_net_name = snaps_utils.get_ext_net_name(self.os_creds)
        self.compute_cnt = snaps_utils.get_active_compute_cnt(self.os_creds)

        LOGGER.debug("Creating image '%s'...", self.image_name)
        image_creator = deploy_utils.create_image(
            self.os_creds, ImageConfig(
                name=self.image_name,
                image_file=self.GLANCE_IMAGE_PATH,
                img_format=self.GLANCE_IMAGE_FORMAT,
                image_user=self.GLANCE_IMAGE_USERNAME,
                public=True,
                extra_properties=self.GLANCE_IMAGE_EXTRA_PROPERTIES))
        if image_creator is None:
            raise Exception("Failed to create image")
        self.creators.append(image_creator)

        LOGGER.debug("Creating network '%s'...", network_name)

        rally_network_type = None
        rally_physical_network = None
        rally_segmentation_id = None

        if hasattr(CONST, 'rally_network_type'):
            rally_network_type = CONST.__getattribute__(
                'rally_network_type')
        if hasattr(CONST, 'rally_physical_network'):
            rally_physical_network = CONST.__getattribute__(
                'rally_physical_network')
        if hasattr(CONST, 'rally_segmentation_id'):
            rally_segmentation_id = CONST.__getattribute__(
                'rally_segmentation_id')

        network_creator = deploy_utils.create_network(
            self.os_creds, NetworkConfig(
                name=network_name,
                shared=True,
                network_type=rally_network_type,
                physical_network=rally_physical_network,
                segmentation_id=rally_segmentation_id,
                subnet_settings=[SubnetConfig(
                    name=subnet_name,
                    cidr=self.RALLY_PRIVATE_SUBNET_CIDR)]))
        if network_creator is None:
            raise Exception("Failed to create private network")
        self.priv_net_id = network_creator.get_network().id
        self.creators.append(network_creator)

        LOGGER.debug("Creating router '%s'...", router_name)
        router_creator = deploy_utils.create_router(
            self.os_creds, RouterConfig(
                name=router_name,
                external_gateway=self.ext_net_name,
                internal_subnets=[subnet_name]))
        if router_creator is None:
            raise Exception("Failed to create router")
        self.creators.append(router_creator)

        LOGGER.debug("Creating flavor '%s'...", self.flavor_name)
        flavor_creator = OpenStackFlavor(
            self.os_creds, FlavorConfig(
                name=self.flavor_name, ram=self.FLAVOR_RAM, disk=1, vcpus=1,
                metadata=self.FLAVOR_EXTRA_SPECS))
        if flavor_creator is None or flavor_creator.create() is None:
            raise Exception("Failed to create flavor")
        self.creators.append(flavor_creator)

        LOGGER.debug("Creating flavor '%s'...", self.flavor_alt_name)
        flavor_alt_creator = OpenStackFlavor(
            self.os_creds, FlavorConfig(
                name=self.flavor_alt_name, ram=self.FLAVOR_RAM_ALT, disk=1,
                vcpus=1, metadata=self.FLAVOR_EXTRA_SPECS))
        if flavor_alt_creator is None or flavor_alt_creator.create() is None:
            raise Exception("Failed to create flavor")
        self.creators.append(flavor_alt_creator)
Exemplo n.º 3
0
    def run(self, **kwargs):  # pylint: disable=too-many-locals
        """
        Begins the test execution which should originate from the subclass
        """
        self.logger.info('Begin virtual environment setup')

        self.start_time = time.time()
        self.logger.info(
            "vPing Start Time:'%s'",
            datetime.fromtimestamp(
                self.start_time).strftime('%Y-%m-%d %H:%M:%S'))

        image_base_name = '{}-{}'.format(getattr(CONST, 'vping_image_name'),
                                         str(self.guid))
        os_image_settings = openstack_tests.cirros_image_settings(
            image_base_name, image_metadata=self.cirros_image_config)
        self.logger.info("Creating image with name: '%s'", image_base_name)

        self.image_creator = deploy_utils.create_image(self.os_creds,
                                                       os_image_settings)
        self.creators.append(self.image_creator)

        private_net_name = getattr(CONST, 'vping_private_net_name') + self.guid
        private_subnet_name = getattr(CONST,
                                      'vping_private_subnet_name') + self.guid
        private_subnet_cidr = getattr(CONST, 'vping_private_subnet_cidr')

        vping_network_type = None
        vping_physical_network = None
        vping_segmentation_id = None

        if hasattr(CONST, 'vping_network_type'):
            vping_network_type = getattr(CONST, 'vping_network_type')
        if hasattr(CONST, 'vping_physical_network'):
            vping_physical_network = getattr(CONST, 'vping_physical_network')
        if hasattr(CONST, 'vping_segmentation_id'):
            vping_segmentation_id = getattr(CONST, 'vping_segmentation_id')

        self.logger.info("Creating network with name: '%s'", private_net_name)
        self.network_creator = deploy_utils.create_network(
            self.os_creds,
            NetworkConfig(name=private_net_name,
                          network_type=vping_network_type,
                          physical_network=vping_physical_network,
                          segmentation_id=vping_segmentation_id,
                          subnet_settings=[
                              SubnetConfig(name=private_subnet_name,
                                           cidr=private_subnet_cidr)
                          ]))
        self.creators.append(self.network_creator)

        # Creating router to external network
        log = "Creating router with name: '%s'" % self.router_name
        self.logger.info(log)
        ext_net_name = snaps_utils.get_ext_net_name(self.os_creds)
        self.router_creator = deploy_utils.create_router(
            self.os_creds,
            RouterConfig(name=self.router_name,
                         external_gateway=ext_net_name,
                         internal_subnets=[private_subnet_name]))
        self.creators.append(self.router_creator)

        self.logger.info("Creating flavor with name: '%s'", self.flavor_name)
        scenario = getattr(CONST, 'DEPLOY_SCENARIO')
        flavor_metadata = None
        flavor_ram = 512
        if 'ovs' in scenario or 'fdio' in scenario:
            flavor_metadata = create_flavor.MEM_PAGE_SIZE_LARGE
            flavor_ram = 1024
        flavor_creator = OpenStackFlavor(
            self.os_creds,
            FlavorConfig(name=self.flavor_name,
                         ram=flavor_ram,
                         disk=1,
                         vcpus=1,
                         metadata=flavor_metadata))
        flavor_creator.create()
        self.creators.append(flavor_creator)