Example #1
0
    def run(self):
        """
        Sets up the OpenStack VM instance objects then executes the ping and
        validates.
        :return: the exit code from the super.execute() method
        """
        try:
            super(VPingUserdata, self).run()

            # 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,
                port_settings=[port1_settings])

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

            userdata = _get_userdata(
                self.vm1_creator.get_port_ip(port1_settings.name))
            if userdata:
                # Creating Instance 2
                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,
                    port_settings=[port2_settings],
                    userdata=userdata)

                self.logger.info(
                    "Creating VM 2 instance with name: '%s'"
                    % instance2_settings.name)
                self.vm2_creator = deploy_utils.create_vm_instance(
                    self.os_creds, instance2_settings,
                    self.image_creator.image_settings)
                self.creators.append(self.vm2_creator)
            else:
                raise Exception('Userdata is None')

            return self._execute()

        finally:
            self._cleanup()
def __create_vm_instances(os_creds_dict, os_users_dict, instances_config,
                          image_dict, keypairs_dict, cleanup=False):
    """
    Returns a dictionary of OpenStackVmInstance objects where the key is the
    instance name
    :param os_creds_dict: Dictionary of OSCreds objects where the key is the
                          name
    :param os_users_dict: Dictionary of OpenStackUser objects where the key is
                          the username
    :param instances_config: The list of VM instance configurations
    :param image_dict: A dictionary of images that will probably be used to
                       instantiate the VM instance
    :param keypairs_dict: A dictionary of keypairs that will probably be used
                          to instantiate the VM instance
    :param cleanup: Denotes whether or not this is being called for cleanup
    :return: dictionary
    """
    vm_dict = {}

    if instances_config:
        for instance_config in instances_config:
            conf = instance_config.get('instance')
            if conf:
                if image_dict:
                    image_creator = image_dict.get(conf.get('imageName'))
                    if image_creator:
                        instance_settings = VmInstanceConfig(
                            **instance_config['instance'])
                        kp_creator = keypairs_dict.get(
                            conf.get('keypair_name'))

                        try:
                            vm_dict[conf[
                                'name']] = deploy_utils.create_vm_instance(
                                __get_creds(
                                    os_creds_dict, os_users_dict, conf),
                                instance_settings,
                                image_creator.image_settings,
                                keypair_creator=kp_creator,
                                init_only=cleanup)
                        except Unauthorized as e:
                            if not cleanup:
                                logger.warn('Unable to initialize VM - %s', e)
                                raise
                    else:
                        raise Exception('Image creator instance not found.'
                                        ' Cannot instantiate')
                else:
                    if not cleanup:
                        raise Exception('Image dictionary is None. Cannot '
                                        'instantiate')
            else:
                raise Exception('Instance configuration is None. Cannot '
                                'instantiate')
        logger.info('Created configured instances')

    return vm_dict
Example #3
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()