예제 #1
0
    def create_compute_resources(self, network_prefix, config_scale):
        """
        Creates the compute resources includes the following resources
        1. VM instances
        2. Security groups
        3. Keypairs
        """
        # Create the security groups first
        for secgroup_count in range(config_scale["secgroups_per_network"]):
            secgroup_instance = base_compute.SecGroup(self.nova_client)
            self.secgroup_list.append(secgroup_instance)
            secgroup_name = network_prefix + "-SG" + str(secgroup_count)
            secgroup_instance.create_secgroup_with_rules(secgroup_name)
            self.res_logger.log("sec_groups", secgroup_instance.secgroup.name, secgroup_instance.secgroup.id)

        LOG.info("Scheduled to create VMs for network %s..." % network_prefix)

        vm_total = config_scale["vms_per_network"]
        if config_scale["use_floatingip"]:
            external_network = find_external_network(self.neutron_client)

        storage_mode = self.router.user.tenant.kloud.storage_mode
        if storage_mode and config_scale["storage_stage_configs"]["target"] == "volume":
            bs_obj = base_storage.BaseStorage(self.cinder_client)
            vol_size = config_scale["storage_stage_configs"]["disk_size"]
        else:
            vol_size = 0

        # Schedule to create the required number of VMs
        for instance_count in xrange(vm_total):
            vm_name = network_prefix + "-I" + str(instance_count)
            perf_instance = PerfInstance(vm_name, self, config_scale)
            self.instance_list.append(perf_instance)

            # Create volume if needed
            # Don't create volumn for KB-Proxy
            if vol_size and instance_count < vm_total - 1:
                vol_name = network_prefix + "-V" + str(instance_count)
                perf_instance.vol = bs_obj.create_vol(vol_size, name=vol_name)
                self.res_logger.log("volumes", vol_name, perf_instance.vol.id)

            perf_instance.subnet_ip = self.network["subnet_ip"]
            if config_scale["use_floatingip"]:
                # Create the floating ip for the instance
                # store it and the ip address in perf_instance object
                perf_instance.fip = create_floating_ip(self.neutron_client, external_network)
                perf_instance.fip_ip = perf_instance.fip["floatingip"]["floating_ip_address"]
                self.res_logger.log(
                    "floating_ips",
                    perf_instance.fip["floatingip"]["floating_ip_address"],
                    perf_instance.fip["floatingip"]["id"],
                )

            # Create the VMs on specified network, first keypair, first secgroup
            perf_instance.boot_info["image_name"] = config_scale["image_name"]
            perf_instance.boot_info["keyname"] = self.router.user.key_name
            perf_instance.boot_info["nic"] = [{"net-id": self.network["id"]}]
            perf_instance.boot_info["sec_group"] = self.secgroup_list[0].secgroup
            perf_instance.boot_info["avail_zone"] = self.router.user.tenant.kloud.get_az()
예제 #2
0
파일: vmtp.py 프로젝트: mikeynap/vmtp
 def create_flow_client(self, client_az, int_net):
     self.client = PerfInstance(self.config.vm_name_client,
                                self.config,
                                self.comp,
                                self.net)
     self.client.display('Creating client VM...')
     self.create_instance(self.client, client_az, int_net)
예제 #3
0
    def create_compute_resources(self, network_prefix, config_scale):
        """
        Creates the compute resources includes the following resources
        1. VM instances
        2. Security groups
        3. Keypairs
        """
        # Create the security groups first
        for secgroup_count in range(config_scale["secgroups_per_network"]):
            secgroup_instance = base_compute.SecGroup(self.nova_client)
            self.secgroup_list.append(secgroup_instance)
            secgroup_name = network_prefix + "-SG" + str(secgroup_count)
            secgroup_instance.create_secgroup_with_rules(secgroup_name)
            self.res_logger.log("sec_groups", secgroup_instance.secgroup.name, secgroup_instance.secgroup.id)

        LOG.info("Scheduled to create VM for network %s..." % network_prefix)
        if config_scale["use_floatingip"]:
            external_network = find_external_network(self.neutron_client)
        # Schedule to create the required number of VMs
        for instance_count in range(config_scale["vms_per_network"]):
            vm_name = network_prefix + "-I" + str(instance_count)
            perf_instance = PerfInstance(vm_name, self, config_scale)
            self.instance_list.append(perf_instance)

            perf_instance.subnet_ip = self.network["subnet_ip"]
            if config_scale["use_floatingip"]:
                # Create the floating ip for the instance
                # store it and the ip address in perf_instance object
                perf_instance.fip = create_floating_ip(self.neutron_client, external_network)
                perf_instance.fip_ip = perf_instance.fip["floatingip"]["floating_ip_address"]
                self.res_logger.log(
                    "floating_ips",
                    perf_instance.fip["floatingip"]["floating_ip_address"],
                    perf_instance.fip["floatingip"]["id"],
                )

            # Create the VMs on specified network, first keypair, first secgroup
            perf_instance.boot_info["image_name"] = config_scale["image_name"]
            perf_instance.boot_info["keyname"] = self.router.user.key_name
            perf_instance.boot_info["nic"] = [{"net-id": self.network["id"]}]
            perf_instance.boot_info["sec_group"] = self.secgroup_list[0].secgroup
            perf_instance.boot_info["avail_zone"] = self.router.user.tenant.kloud.get_az()
예제 #4
0
    def create_compute_resources(self, network_prefix, config_scale):
        """
        Creates the compute resources includes the following resources
        1. VM instances
        2. Security groups
        3. Keypairs
        """
        # Create the security groups first
        for secgroup_count in range(config_scale['secgroups_per_network']):
            secgroup_instance = base_compute.SecGroup(self.nova_client, self.neutron_client)
            self.secgroup_list.append(secgroup_instance)
            secgroup_name = network_prefix + "-SG" + str(secgroup_count)
            secgroup_instance.create_secgroup_with_rules(secgroup_name)
            self.res_logger.log('sec_groups', secgroup_instance.secgroup['name'],
                                secgroup_instance.secgroup['id'])

        LOG.info("Scheduled to create VMs for network %s..." % network_prefix)

        vm_total = config_scale['vms_per_network']
        if config_scale['use_floatingip']:
            external_network = find_external_network(self.neutron_client)

        storage_mode = self.router.user.tenant.kloud.storage_mode
        if storage_mode and config_scale['storage_stage_configs']['target'] == 'volume':
            bs_obj = base_storage.BaseStorage(self.cinder_client)
            vol_size = config_scale['storage_stage_configs']['disk_size']
        else:
            vol_size = 0

        # Schedule to create the required number of VMs
        for instance_count in xrange(vm_total):
            vm_name = network_prefix + "-I" + str(instance_count)
            perf_instance = PerfInstance(vm_name, self, config_scale)
            self.instance_list.append(perf_instance)

            # Create volume if needed
            # Don't create volumn for KB-Proxy
            if vol_size and instance_count < vm_total - 1:
                vol_name = network_prefix + "-V" + str(instance_count)
                perf_instance.vol = bs_obj.create_vol(vol_size, name=vol_name)
                self.res_logger.log('volumes', vol_name, perf_instance.vol.id)

            perf_instance.subnet_ip = self.network['subnet_ip']
            if config_scale['use_floatingip']:
                # Create the floating ip for the instance
                # store it and the ip address in perf_instance object
                perf_instance.fip = create_floating_ip(self.neutron_client, external_network)
                perf_instance.fip_ip = perf_instance.fip['floatingip']['floating_ip_address']
                self.res_logger.log('floating_ips',
                                    perf_instance.fip['floatingip']['floating_ip_address'],
                                    perf_instance.fip['floatingip']['id'])

            # Create the VMs on specified network, first keypair, first secgroup
            perf_instance.boot_info['image_name'] = config_scale['image_name']
            perf_instance.boot_info['keyname'] = self.router.user.key_name
            perf_instance.boot_info['nic'] = [{'net-id': self.network['id']}]
            perf_instance.boot_info['sec_group'] = self.secgroup_list[0].secgroup
            perf_instance.boot_info['avail_zone'] = self.router.user.tenant.kloud.get_az()
예제 #5
0
파일: vmtp.py 프로젝트: mikeynap/vmtp
def test_native_tp(nhosts, ifname, config):
    FlowPrinter.print_desc('Native Host to Host throughput')
    result_list = []
    server_host = nhosts[0]
    server = PerfInstance('Host-' + server_host.host + '-Server', config, server=True)

    if not server.setup_ssh(server_host):
        server.display('SSH failed, check IP or make sure public key is configured')
    else:
        server.display('SSH connected')
        server.create()
        # if inter-node-only requested we avoid running the client on the
        # same node as the server - but only if there is at least another
        # IP provided
        if config.inter_node_only and len(nhosts) > 1:
            # remove the first element of the list
            nhosts.pop(0)
        # IP address clients should connect to, check if the user
        # has passed a server listen interface name
        if ifname:
            # use the IP address configured on given interface
            server_ip = server.get_interface_ip(ifname)
            if not server_ip:
                print('Error: cannot get IP address for interface ' + ifname)
            else:
                server.display('Clients will use server IP address %s (%s)' %
                               (server_ip, ifname))
        else:
            # use same as ssh IP
            server_ip = server_host.host

        if server_ip:
            # start client side, 1 per host provided
            for client_host in nhosts:
                client = PerfInstance('Host-' + client_host.host + '-Client', config)
                if not client.setup_ssh(client_host):
                    client.display('SSH failed, check IP or make sure public key is configured')
                else:
                    client.buginf('SSH connected')
                    client.create()
                    if client_host == server_host:
                        desc = 'Native intra-host'
                    else:
                        desc = 'Native inter-host'
                    res = client.run_client(desc,
                                            server_ip,
                                            server,
                                            bandwidth=config.vm_bandwidth)
                    result_list.append(res)
                client.dispose()
    server.dispose()

    return result_list
예제 #6
0
파일: vmtp.py 프로젝트: mikeynap/vmtp
 def ext_host_tp_test(self):
     client = PerfInstance('Host-' + self.config.ext_host.host + '-Client', self.config)
     if not client.setup_ssh(self.config.ext_host):
         client.display('SSH to ext host failed, check IP or make sure public key is configured')
     else:
         client.buginf('SSH connected')
         client.create()
         FlowPrinter.print_desc('External-VM (upload/download)')
         target_ip = self.server.ssh_access.host
         if self.config.same_network_only:
             target_ip = self.server.internal_ip
         res = client.run_client('External-VM',
                                 target_ip,
                                 self.server,
                                 bandwidth=self.config.vm_bandwidth,
                                 bidirectional=True)
         if res:
             self.rescol.add_flow_result(res)
         client.dispose()
예제 #7
0
파일: vmtp.py 프로젝트: mikeynap/vmtp
    def setup(self):
        # This is a template host access that will be used for all instances
        # (the only specific field specific to each instance is the host IP)
        # For test VM access, we never use password and always need a key pair
        self.instance_access = sshutils.SSHAccess()
        self.instance_access.username = self.config.ssh_vm_username
        # if the configuration does not have a
        # key pair specified, we check if the user has a personal key pair
        # if no key pair is configured or usable, a temporary key pair will be created
        if self.config.public_key_file and self.config.private_key_file:
            self.instance_access.public_key_file = self.config.public_key_file
            self.instance_access.private_key_file = self.config.private_key_file
        else:
            pub_key = os.path.expanduser('~/.ssh/id_rsa.pub')
            priv_key = os.path.expanduser('~/.ssh/id_rsa')
            if os.path.isfile(pub_key) and os.path.isfile(priv_key):
                self.instance_access.public_key_file = pub_key
                self.instance_access.private_key_file = priv_key
            else:
                print('Error: Default keypair ~/.ssh/id_rsa[.pub] does not exist. Please '
                      'either create one in your home directory, or specify your keypair '
                      'information in the config file before running VMTP.')
                sys.exit(1)

        if self.config.debug and self.instance_access.public_key_file:
            print('VM public key:  ' + self.instance_access.public_key_file)
            print('VM private key: ' + self.instance_access.private_key_file)

        # If we need to reuse existing vms just return without setup
        if not self.config.reuse_existing_vm:
            creds = self.cred.get_credentials()
            creds_nova = self.cred.get_nova_credentials_v2()
            # Create the nova and neutron instances
            nova_client = Client(**creds_nova)
            neutron = neutronclient.Client(**creds)

            self.comp = compute.Compute(nova_client, self.config)

            # Add the appropriate public key to openstack
            self.comp.init_key_pair(self.config.public_key_name, self.instance_access)

            self.image_instance = self.comp.find_image(self.config.image_name)
            if self.image_instance is None:
                if self.config.vm_image_url != "":
                    print '%s: image for VM not found, trying to upload it ...' \
                        % (self.config.image_name)
                    keystone = keystoneclient.Client(**creds)
                    glance_endpoint = keystone.service_catalog.url_for(
                        service_type='image', endpoint_type='publicURL')
                    self.glance_client = glanceclient.Client(
                        glance_endpoint, token=keystone.auth_token,
                        cacert=creds['cacert'])
                    self.comp.upload_image_via_url(
                        self.glance_client,
                        self.config.image_name,
                        self.config.vm_image_url)
                    self.image_instance = self.comp.find_image(self.config.image_name)
                    self.image_uploaded = True
                else:
                    # Exit the pogram
                    print '%s: image to launch VM not found. ABORTING.' \
                        % (self.config.image_name)
                    sys.exit(1)

            self.assert_true(self.image_instance)
            print 'Found image %s to launch VM, will continue' % (self.config.image_name)
            self.flavor_type = self.comp.find_flavor(self.config.flavor_type)
            self.net = network.Network(neutron, self.config)

            self.rescol.add_property('l2agent_type', self.net.l2agent_type)
            print "OpenStack agent: " + self.net.l2agent_type
            try:
                network_type = self.net.vm_int_net[0]['provider:network_type']
                print "OpenStack network type: " + network_type
                self.rescol.add_property('encapsulation', network_type)
            except KeyError as exp:
                network_type = 'Unknown'
                print "Provider network type not found: ", str(exp)

        # Create a new security group for the test
        self.sec_group = self.comp.security_group_create()
        if not self.sec_group:
            raise VmtpException("Security group creation failed")
        if self.config.reuse_existing_vm:
            self.server.internal_ip = self.config.vm_server_internal_ip
            self.client.internal_ip = self.config.vm_client_internal_ip
            if self.config.vm_server_external_ip:
                self.server.ssh_access.host = self.config.vm_server_external_ip
            else:
                self.server.ssh_access.host = self.config.vm_server_internal_ip
            if self.config.vm_client_external_ip:
                self.client.ssh_access.host = self.config.vm_client_external_ip
            else:
                self.client.ssh_access.host = self.config.vm_client_internal_ip
            return

        # this is the standard way of running the test
        # NICs to be used for the VM
        if self.config.reuse_network_name:
            # VM needs to connect to existing management and new data network
            # Reset the management network name
            int_net_name = list(self.config.internal_network_name)
            int_net_name[0] = self.config.reuse_network_name
            self.config.internal_network_name = int_net_name
        else:
            # Make sure we have an external network and an external router
            self.assert_true(self.net.ext_net)
            self.assert_true(self.net.ext_router)
            self.assert_true(self.net.vm_int_net)

        # Get hosts for the availability zone to use
        # avail_list = self.comp.list_hypervisor(config.availability_zone)
        avail_list = self.comp.get_az_host_list()
        if not avail_list:
            sys.exit(5)

        # compute the list of client vm placements to run
        # the first host is always where the server runs
        server_az = avail_list[0]
        if len(avail_list) > 1:
            # 2 hosts are known
            if self.config.inter_node_only:
                # in this case we do not want the client to run on the same host
                # as the server
                avail_list.pop(0)
        self.client_az_list = avail_list

        self.server = PerfInstance(self.config.vm_name_server,
                                   self.config,
                                   self.comp,
                                   self.net,
                                   server=True)
        self.server.display('Creating server VM...')
        self.create_instance(self.server, server_az,
                             self.net.vm_int_net[0])
예제 #8
0
파일: vmtp.py 프로젝트: mikeynap/vmtp
class VmtpTest(object):
    def __init__(self, config, cred, rescol):
        '''
            1. Authenticate nova and neutron with keystone
            2. Create new client objects for neutron and nova
            3. Find external network
            4. Find or create router for external network
            5. Find or create internal mgmt and data networks
            6. Add internal mgmt network to router
            7. Import public key for ssh
            8. Create 2 VM instances on internal networks
            9. Create floating ips for VMs
            10. Associate floating ip with VMs
        '''
        self.server = None
        self.client = None
        self.net = None
        self.comp = None
        self.ping_status = None
        self.client_az_list = None
        self.sec_group = None
        self.image_instance = None
        self.flavor_type = None
        self.instance_access = None
        self.glance_client = None
        self.image_uploaded = False
        self.rescol = rescol
        self.config = config
        self.cred = cred

    # Create an instance on a particular availability zone
    def create_instance(self, inst, az, int_net):
        fn = self.config.user_data_file
        user_data_file = fn if fn and os.path.isfile(fn) else None
        self.assert_true(inst.create(self.image_instance,
                                     self.flavor_type,
                                     self.instance_access,
                                     int_net,
                                     az,
                                     int_net['name'],
                                     self.sec_group,
                                     init_file_name=user_data_file))

    def assert_true(self, cond):
        if not cond:
            raise VmtpException('Assert failure')

    def setup(self):
        # This is a template host access that will be used for all instances
        # (the only specific field specific to each instance is the host IP)
        # For test VM access, we never use password and always need a key pair
        self.instance_access = sshutils.SSHAccess()
        self.instance_access.username = self.config.ssh_vm_username
        # if the configuration does not have a
        # key pair specified, we check if the user has a personal key pair
        # if no key pair is configured or usable, a temporary key pair will be created
        if self.config.public_key_file and self.config.private_key_file:
            self.instance_access.public_key_file = self.config.public_key_file
            self.instance_access.private_key_file = self.config.private_key_file
        else:
            pub_key = os.path.expanduser('~/.ssh/id_rsa.pub')
            priv_key = os.path.expanduser('~/.ssh/id_rsa')
            if os.path.isfile(pub_key) and os.path.isfile(priv_key):
                self.instance_access.public_key_file = pub_key
                self.instance_access.private_key_file = priv_key
            else:
                print('Error: Default keypair ~/.ssh/id_rsa[.pub] does not exist. Please '
                      'either create one in your home directory, or specify your keypair '
                      'information in the config file before running VMTP.')
                sys.exit(1)

        if self.config.debug and self.instance_access.public_key_file:
            print('VM public key:  ' + self.instance_access.public_key_file)
            print('VM private key: ' + self.instance_access.private_key_file)

        # If we need to reuse existing vms just return without setup
        if not self.config.reuse_existing_vm:
            creds = self.cred.get_credentials()
            creds_nova = self.cred.get_nova_credentials_v2()
            # Create the nova and neutron instances
            nova_client = Client(**creds_nova)
            neutron = neutronclient.Client(**creds)

            self.comp = compute.Compute(nova_client, self.config)

            # Add the appropriate public key to openstack
            self.comp.init_key_pair(self.config.public_key_name, self.instance_access)

            self.image_instance = self.comp.find_image(self.config.image_name)
            if self.image_instance is None:
                if self.config.vm_image_url != "":
                    print '%s: image for VM not found, trying to upload it ...' \
                        % (self.config.image_name)
                    keystone = keystoneclient.Client(**creds)
                    glance_endpoint = keystone.service_catalog.url_for(
                        service_type='image', endpoint_type='publicURL')
                    self.glance_client = glanceclient.Client(
                        glance_endpoint, token=keystone.auth_token,
                        cacert=creds['cacert'])
                    self.comp.upload_image_via_url(
                        self.glance_client,
                        self.config.image_name,
                        self.config.vm_image_url)
                    self.image_instance = self.comp.find_image(self.config.image_name)
                    self.image_uploaded = True
                else:
                    # Exit the pogram
                    print '%s: image to launch VM not found. ABORTING.' \
                        % (self.config.image_name)
                    sys.exit(1)

            self.assert_true(self.image_instance)
            print 'Found image %s to launch VM, will continue' % (self.config.image_name)
            self.flavor_type = self.comp.find_flavor(self.config.flavor_type)
            self.net = network.Network(neutron, self.config)

            self.rescol.add_property('l2agent_type', self.net.l2agent_type)
            print "OpenStack agent: " + self.net.l2agent_type
            try:
                network_type = self.net.vm_int_net[0]['provider:network_type']
                print "OpenStack network type: " + network_type
                self.rescol.add_property('encapsulation', network_type)
            except KeyError as exp:
                network_type = 'Unknown'
                print "Provider network type not found: ", str(exp)

        # Create a new security group for the test
        self.sec_group = self.comp.security_group_create()
        if not self.sec_group:
            raise VmtpException("Security group creation failed")
        if self.config.reuse_existing_vm:
            self.server.internal_ip = self.config.vm_server_internal_ip
            self.client.internal_ip = self.config.vm_client_internal_ip
            if self.config.vm_server_external_ip:
                self.server.ssh_access.host = self.config.vm_server_external_ip
            else:
                self.server.ssh_access.host = self.config.vm_server_internal_ip
            if self.config.vm_client_external_ip:
                self.client.ssh_access.host = self.config.vm_client_external_ip
            else:
                self.client.ssh_access.host = self.config.vm_client_internal_ip
            return

        # this is the standard way of running the test
        # NICs to be used for the VM
        if self.config.reuse_network_name:
            # VM needs to connect to existing management and new data network
            # Reset the management network name
            int_net_name = list(self.config.internal_network_name)
            int_net_name[0] = self.config.reuse_network_name
            self.config.internal_network_name = int_net_name
        else:
            # Make sure we have an external network and an external router
            self.assert_true(self.net.ext_net)
            self.assert_true(self.net.ext_router)
            self.assert_true(self.net.vm_int_net)

        # Get hosts for the availability zone to use
        # avail_list = self.comp.list_hypervisor(config.availability_zone)
        avail_list = self.comp.get_az_host_list()
        if not avail_list:
            sys.exit(5)

        # compute the list of client vm placements to run
        # the first host is always where the server runs
        server_az = avail_list[0]
        if len(avail_list) > 1:
            # 2 hosts are known
            if self.config.inter_node_only:
                # in this case we do not want the client to run on the same host
                # as the server
                avail_list.pop(0)
        self.client_az_list = avail_list

        self.server = PerfInstance(self.config.vm_name_server,
                                   self.config,
                                   self.comp,
                                   self.net,
                                   server=True)
        self.server.display('Creating server VM...')
        self.create_instance(self.server, server_az,
                             self.net.vm_int_net[0])

    # Test throughput for the case of the external host
    def ext_host_tp_test(self):
        client = PerfInstance('Host-' + self.config.ext_host.host + '-Client', self.config)
        if not client.setup_ssh(self.config.ext_host):
            client.display('SSH to ext host failed, check IP or make sure public key is configured')
        else:
            client.buginf('SSH connected')
            client.create()
            FlowPrinter.print_desc('External-VM (upload/download)')
            target_ip = self.server.ssh_access.host
            if self.config.same_network_only:
                target_ip = self.server.internal_ip
            res = client.run_client('External-VM',
                                    target_ip,
                                    self.server,
                                    bandwidth=self.config.vm_bandwidth,
                                    bidirectional=True)
            if res:
                self.rescol.add_flow_result(res)
            client.dispose()

    def add_location(self, label):
        '''Add a note to a label to specify same node or differemt node.'''
        # We can only tell if there is a host part in the az
        # e.g. 'nova:GG34-7'
        if ':' in self.client.az:
            if self.client.az == self.server.az:
                return label + ' (intra-node)'
            else:
                return label + ' (inter-node)'
        return label

    def create_flow_client(self, client_az, int_net):
        self.client = PerfInstance(self.config.vm_name_client,
                                   self.config,
                                   self.comp,
                                   self.net)
        self.client.display('Creating client VM...')
        self.create_instance(self.client, client_az, int_net)

    def measure_flow(self, label, target_ip):
        label = self.add_location(label)
        FlowPrinter.print_desc(label)

        # results for this flow as a dict
        perf_output = self.client.run_client(label, target_ip,
                                             self.server,
                                             bandwidth=self.config.vm_bandwidth,
                                             az_to=self.server.az)
        if self.config.stop_on_error:
            # check if there is any error in the results
            results_list = perf_output['results']
            for res_dict in results_list:
                if 'error' in res_dict:
                    print('Stopping execution on error, cleanup all VMs/networks manually')
                    self.rescol.pprint(perf_output)
                    sys.exit(2)

        self.rescol.add_flow_result(perf_output)

    def measure_vm_flows(self):
        # scenarios need to be tested for both inter and intra node
        # 1. VM to VM on same data network
        # 2. VM to VM on seperate networks fixed-fixed
        # 3. VM to VM on seperate networks floating-floating

        # we should have 1 or 2 AZ to use (intra and inter-node)
        for client_az in self.client_az_list:
            self.create_flow_client(client_az, self.net.vm_int_net[0])
            self.measure_flow("VM to VM same network fixed IP",
                              self.server.internal_ip)
            self.client.dispose()
            self.client = None
            if not self.config.reuse_network_name and not self.config.same_network_only:
                # Different network
                self.create_flow_client(client_az, self.net.vm_int_net[1])

                self.measure_flow("VM to VM different network fixed IP",
                                  self.server.internal_ip)
                if not self.config.ipv6_mode:
                    self.measure_flow("VM to VM different network floating IP",
                                      self.server.ssh_access.host)

                self.client.dispose()
                self.client = None

        # If external network is specified run that case
        if self.config.ext_host:
            self.ext_host_tp_test()

    def teardown(self):
        '''
            Clean up the floating ip and VMs
        '''
        print '---- Cleanup ----'
        if self.server:
            self.server.dispose()
        if self.client:
            self.client.dispose()
        if not self.config.reuse_existing_vm and self.net:
            self.net.dispose()
        # Remove the public key
        if self.comp:
            self.comp.remove_public_key(self.config.public_key_name)
        # Finally remove the security group
        try:
            if self.comp:
                self.comp.security_group_delete(self.sec_group)
        except ClientException:
            # May throw novaclient.exceptions.BadRequest if in use
            print('Security group in use: not deleted')
        if self.image_uploaded and self.config.delete_image_after_run:
            self.comp.delete_image(self.glance_client, self.config.image_name)

    def run(self):
        error_flag = False

        try:
            self.setup()
            self.measure_vm_flows()
        except KeyboardInterrupt:
            traceback.format_exc()
        except (VmtpException, sshutils.SSHError, ClientException, Exception):
            print 'print_exc:'
            traceback.print_exc()
            error_flag = True

        if self.config.stop_on_error and error_flag:
            print('Stopping execution on error, cleanup all VMs/networks manually')
            sys.exit(2)
        else:
            self.teardown()
예제 #9
0
파일: vmtp.py 프로젝트: danielmellado/vmtp
 def create_flow_client(self, client_az, int_net):
     self.client = PerfInstance(config.vm_name_client, config,
                                self.comp,
                                self.net)
     self.create_instance(self.client, client_az, int_net)
예제 #10
0
파일: vmtp.py 프로젝트: danielmellado/vmtp
 def ext_host_tp_test(self):
     client = PerfInstance('Host-' + ext_host_list[1] + '-Client', config)
     if not client.setup_ssh(ext_host_list[1], ext_host_list[0]):
         client.display('SSH failed, check IP or make sure public key is configured')
     else:
         client.buginf('SSH connected')
         client.create()
         fpr.print_desc('External-VM (upload/download)')
         res = client.run_client('External-VM',
                                 self.server.ssh_ip,
                                 self.server,
                                 bandwidth=config.vm_bandwidth,
                                 bidirectional=True)
         if res:
             rescol.add_flow_result(res)
         client.dispose()
예제 #11
0
파일: vmtp.py 프로젝트: danielmellado/vmtp
    def setup(self):
        # If we need to reuse existing vms just return without setup
        if not config.reuse_existing_vm:
            creds = cred.get_credentials()
            creds_nova = cred.get_nova_credentials_v2()
            # Create the nova and neutron instances
            nova_client = Client(**creds_nova)
            neutron = neutronclient.Client(**creds)

            self.comp = compute.Compute(nova_client, config)
            # Add the script public key to openstack
            self.comp.add_public_key(config.public_key_name,
                                     config.public_key_file)

            self.image_instance = self.comp.find_image(config.image_name)
            if self.image_instance is None:
                if config.vm_image_url is not None:
                    print '%s: image for VM not found, uploading it ...' \
                        % (config.image_name)
                    keystone = keystoneclient.Client(**creds)
                    glance_endpoint = keystone.service_catalog.url_for(
                        service_type='image', endpoint_type='publicURL')
                    glance_client = glanceclient.Client(
                        glance_endpoint, token=keystone.auth_token)
                    self.comp.upload_image_via_url(
                        glance_client, config.image_name, config.vm_image_url)
                    self.image_instance = self.comp.find_image(config.image_name)
                else:
                    # Exit the pogram
                    print '%s: image to launch VM not found. ABORTING.' \
                        % (config.image_name)
                    sys.exit(1)

            self.assert_true(self.image_instance)
            print 'Found image %s to launch VM, will continue' % (config.image_name)
            self.flavor_type = self.comp.find_flavor(config.flavor_type)
            self.net = network.Network(neutron, config)

            rescol.add_property('l2agent_type', self.net.l2agent_type)
            print "OpenStack agent: " + self.net.l2agent_type
            try:
                network_type = self.net.vm_int_net[0]['provider:network_type']
                print "OpenStack network type: " + network_type
                rescol.add_property('encapsulation', network_type)
            except KeyError as exp:
                network_type = 'Unknown'
                print "Provider network type not found: ", str(exp)

        # Create a new security group for the test
        self.sec_group = self.comp.security_group_create()
        if not self.sec_group:
            raise VmtpException("Security group creation failed")
        if config.reuse_existing_vm:
            self.server.internal_ip = config.vm_server_internal_ip
            self.client.internal_ip = config.vm_client_internal_ip
            if config.vm_server_external_ip:
                self.server.ssh_ip = config.vm_server_external_ip
            else:
                self.server.ssh_ip = config.vm_server_internal_ip
            if config.vm_client_external_ip:
                self.client.ssh_ip = config.vm_client_external_ip
            else:
                self.client.ssh_ip = config.vm_client_internal_ip
            return

        # this is the standard way of running the test
        # NICs to be used for the VM
        if config.reuse_network_name:
            # VM needs to connect to existing management and new data network
            # Reset the management network name
            config.internal_network_name[0] = config.reuse_network_name
        else:
            # Make sure we have an external network and an external router
            self.assert_true(self.net.ext_net)
            self.assert_true(self.net.ext_router)
            self.assert_true(self.net.vm_int_net)

        # Get hosts for the availability zone to use
        # avail_list = self.comp.list_hypervisor(config.availability_zone)
        avail_list = self.comp.get_az_host_list()
        if not avail_list:
            sys.exit(5)

        # compute the list of client vm placements to run
        # the first host is always where the server runs
        server_az = avail_list[0]
        if len(avail_list) > 1:
            # 2 hosts are known
            if config.inter_node_only:
                # in this case we do not want the client to run on the same host
                # as the server
                avail_list.pop(0)
        self.client_az_list = avail_list

        self.server = PerfInstance(config.vm_name_server,
                                   config,
                                   self.comp,
                                   self.net,
                                   server=True)
        self.server.display('Creating server VM...')
        self.create_instance(self.server, server_az,
                             self.net.vm_int_net[0])