Пример #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 = PortConfig(
                name=self.vm1_name + '-vPingPort',
                network_name=self.network_creator.network_settings.name)
            instance1_settings = VmInstanceConfig(
                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 = PortConfig(
                    name=self.vm2_name + '-vPingPort',
                    network_name=self.network_creator.network_settings.name)
                instance2_settings = VmInstanceConfig(
                    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()
Пример #2
0
def __create_port_configs(neutron, ports):
    """
    Returns a list of PortConfig objects based on the networks parameter
    :param neutron: the neutron client
    :param ports: a list of SNAPS-OO Port domain objects
    :return:
    """
    out = list()

    for port in ports:
        if port.device_owner != 'network:dhcp':
            ip_addrs = list()
            for ip_dict in port.ips:
                subnet = neutron_utils.get_subnet_by_id(
                    neutron, ip_dict['subnet_id'])
                ip_addrs.append({
                    'subnet_name': subnet.name,
                    'ip': ip_dict['ip_address']
                })

            network = neutron_utils.get_network_by_id(neutron, port.network_id)
            kwargs = dict()
            if port.name:
                kwargs['name'] = port.name
            kwargs['network_name'] = network.name
            kwargs['mac_address'] = port.mac_address
            kwargs['allowed_address_pairs'] = port.allowed_address_pairs
            kwargs['admin_state_up'] = port.admin_state_up
            kwargs['ip_addrs'] = ip_addrs
            out.append(PortConfig(**kwargs))

    return out
Пример #3
0
 def test_config_all(self):
     settings = RouterSettings(
         **{
             'name':
             'foo',
             'project_name':
             'bar',
             'external_gateway':
             'foo_gateway',
             'admin_state_up':
             True,
             'enable_snat':
             False,
             'internal_subnets': ['10.0.0.1/24'],
             'interfaces': [{
                 'port': {
                     'name': 'foo-port',
                     'network_name': 'bar-net'
                 }
             }]
         })
     self.assertEqual('foo', settings.name)
     self.assertEqual('bar', settings.project_name)
     self.assertEqual('foo_gateway', settings.external_gateway)
     self.assertTrue(settings.admin_state_up)
     self.assertFalse(settings.enable_snat)
     self.assertIsNotNone(settings.internal_subnets)
     self.assertTrue(isinstance(settings.internal_subnets, list))
     self.assertEqual(1, len(settings.internal_subnets))
     self.assertEqual(['10.0.0.1/24'], settings.internal_subnets)
     self.assertEqual(
         [PortConfig(**{
             'name': 'foo-port',
             'network_name': 'bar-net'
         })], settings.port_settings)
Пример #4
0
    def setUp(self):
        """
        Setup objects required by VM instances
        :return:
        """

        guid = self.__class__.__name__ + '-' + str(uuid.uuid4())

        self.nova = nova_utils.nova_client(self.os_creds, self.os_session)
        self.cinder = cinder_utils.cinder_client(
            self.os_creds, self.os_session)

        self.image_creator = None
        self.network_creator = None
        self.flavor_creator = None
        self.volume_creator = None
        self.instance_creator = None

        try:
            image_settings = openstack_tests.cirros_image_settings(
                name=guid + '-image', image_metadata=self.image_metadata)
            self.image_creator = OpenStackImage(
                self.os_creds, image_settings=image_settings)
            self.image_creator.create()

            network_settings = openstack_tests.get_priv_net_config(
                project_name=self.os_creds.project_name,
                net_name="{}-{}".format(guid, 'net'),
                subnet_name="{}-{}".format(guid, 'subnet')).network_settings

            self.network_creator = OpenStackNetwork(
                self.os_creds, network_settings)
            self.network_creator.create()

            flavor_settings = openstack_tests.get_flavor_config(
                name=guid + '-flavor', ram=256, disk=10, vcpus=1,
                metadata=self.flavor_metadata)
            self.flavor_creator = OpenStackFlavor(
                self.os_creds, flavor_settings)
            self.flavor_creator.create()

            # Create Volume
            volume_settings = VolumeConfig(
                name=self.__class__.__name__ + '-' + str(guid))
            self.volume_creator = OpenStackVolume(
                self.os_creds, volume_settings)
            self.volume_creator.create(block=True)

            port_settings = PortConfig(
                name=guid + '-port', network_name=network_settings.name)
            instance_settings = VmInstanceConfig(
                name=guid + '-vm_inst',
                flavor=self.flavor_creator.flavor_settings.name,
                port_settings=[port_settings])
            self.instance_creator = OpenStackVmInstance(
                self.os_creds, instance_settings, image_settings)
            self.instance_creator.create(block=True)
        except:
            self.tearDown()
            raise
Пример #5
0
    def setUp(self):
        """
        Setup objects required by VM instances
        :return:
        """

        guid = self.__class__.__name__ + '-' + str(uuid.uuid4())

        self.nova = nova_utils.nova_client(
            self.os_creds, self.os_session)
        self.keystone = keystone_utils.keystone_client(
            self.os_creds, self.os_session)
        self.neutron = neutron_utils.neutron_client(
            self.os_creds, self.os_session)
        self.glance = glance_utils.glance_client(
            self.os_creds, self.os_session)

        self.image_creator = None
        self.network_creator = None
        self.flavor_creator = None
        self.port = None
        self.vm_inst = None

        try:
            image_settings = openstack_tests.cirros_image_settings(
                name=guid + '-image', image_metadata=self.image_metadata)
            self.image_creator = OpenStackImage(
                self.os_creds, image_settings=image_settings)
            self.image_creator.create()

            network_settings = openstack_tests.get_priv_net_config(
                project_name=self.os_creds.project_name,
                net_name="{}-{}".format(guid, 'net'),
                subnet_name="{}-{}".format(guid, 'subnet')).network_settings
            self.network_creator = OpenStackNetwork(
                self.os_creds, network_settings)
            self.network_creator.create()

            flavor_config = openstack_tests.get_flavor_config(
                name="{}-{}".format(guid, 'flavor-name'), ram=256, disk=10,
                vcpus=1, metadata=self.flavor_metadata)
            self.flavor_creator = OpenStackFlavor(self.os_creds, flavor_config)
            self.flavor_creator.create()

            port_settings = PortConfig(
                name=guid + '-port', network_name=network_settings.name)
            self.port = neutron_utils.create_port(
                self.neutron, self.os_creds, port_settings)

            self.instance_settings = VmInstanceConfig(
                name=guid + '-vm_inst',
                flavor=self.flavor_creator.flavor_settings.name,
                port_settings=[port_settings])
        except:
            self.tearDown()
            raise
Пример #6
0
def __parse_ports_config(config):
    """
    Parses the "ports" configuration
    :param config: The dictionary to parse
    :return: a list of PortConfig objects
    """
    out = list()
    for port_config in config:
        out.append(PortConfig(**port_config.get('port')))
    return out
Пример #7
0
    def __init__(self, **kwargs):
        """
        Constructor - all parameters are optional
        :param name: The router name.
        :param project_name: The name of the project who owns the network. Only
                             administrative users can specify a project ID
                             other than their own. You cannot change this value
                             through authorization policies.
        :param external_gateway: Name of the external network to which to route
        :param admin_state_up: The administrative status of the router.
                               True = up / False = down (default True)
        :param internal_subnets: List of subnet names to which to connect this
                                 router (this way is deprecated).
                                 *** NEW WAY ***
                                 List of dict where the key is 'subnet' that
                                 contains members with the following keys:
                                 project_name, network_name, and subnet_name
        :param port_settings: List of PortConfig objects
        :return:
        """
        self.name = kwargs.get('name')
        self.project_name = kwargs.get('project_name')
        self.external_gateway = kwargs.get('external_gateway')

        self.admin_state_up = kwargs.get('admin_state_up', True)
        self.enable_snat = kwargs.get('enable_snat')
        if kwargs.get('internal_subnets'):
            self.internal_subnets = kwargs['internal_subnets']
            if isinstance(self.internal_subnets, dict):
                if 'subnet' not in self.internal_subnets:
                    raise RouterConfigError(
                        'subnet is a required key to internal_subnets')
                if 'project_name' not in self.internal_subnets['subnet']:
                    raise RouterConfigError(
                        'subnet.project is a required key to subnet')
                if 'network_name' not in self.internal_subnets['subnet']:
                    raise RouterConfigError(
                        'network_name is a required key to subnet')
                if 'subnet_name' not in self.internal_subnets['subnet']:
                    raise RouterConfigError(
                        'subnet_name is a required key to subnet')
        else:
            self.internal_subnets = list()

        self.port_settings = list()
        if kwargs.get('interfaces', kwargs.get('port_settings')):
            interfaces = kwargs.get('interfaces', kwargs.get('port_settings'))
            for interface in interfaces:
                if isinstance(interface, PortConfig):
                    self.port_settings.append(interface)
                else:
                    self.port_settings.append(PortConfig(**interface['port']))

        if not self.name:
            raise RouterConfigError('Name is required')
Пример #8
0
    def test_vping_ssh(self, create_vm, path_exists, flavor_create,
                       get_port_ip, vm_active, ssh_active, ssh_client,
                       scp_client, trans_script, do_vping_ssh, ext_net_name):
        os_vm_inst = mock.MagicMock(name='get_console_output')
        os_vm_inst.get_console_output.return_value = 'vPing OK'
        ssh_client = mock.MagicMock(name='get_transport')
        ssh_client.get_transport.return_value = None
        scp_client = mock.MagicMock(name='put')
        scp_client.put.return_value = None

        with mock.patch('snaps.openstack.utils.deploy_utils.create_image',
                        return_value=OpenStackImage(self.os_creds, None)), \
                mock.patch('snaps.openstack.utils.deploy_utils.create_network',
                           return_value=OpenStackNetwork(
                               self.os_creds,
                               NetworkConfig(
                                   name='foo',
                                   subnet_settings=[
                                       SubnetConfig(
                                           name='bar',
                                           cidr='10.0.0.1/24')]))), \
                mock.patch('snaps.openstack.utils.deploy_utils.'
                           'create_vm_instance',
                           return_value=OpenStackVmInstance(
                               self.os_creds,
                               VmInstanceConfig(
                                   name='foo', flavor='bar',
                                   port_settings=[PortConfig(
                                       name='foo', network_name='bar')]),
                               None)), \
                mock.patch('snaps.openstack.utils.deploy_utils.create_keypair',
                           return_value=OpenStackKeypair(
                               self.os_creds, KeypairConfig(name='foo'))), \
                mock.patch('snaps.openstack.utils.deploy_utils.create_router',
                           return_value=OpenStackRouter(
                               self.os_creds, RouterConfig(name='foo'))), \
                mock.patch('snaps.openstack.utils.deploy_utils.'
                           'create_security_group',
                           return_value=OpenStackSecurityGroup(
                               self.os_creds,
                               SecurityGroupConfig(name='foo'))), \
                mock.patch('snaps.openstack.create_instance.'
                           'OpenStackVmInstance.'
                           'get_vm_inst', return_value=os_vm_inst), \
                mock.patch('snaps.openstack.create_instance.'
                           'OpenStackVmInstance.'
                           'ssh_client', return_value=ssh_client):
            self.assertEquals(TestCase.EX_OK, self.vping_ssh.run())
Пример #9
0
 def test_all_internal_subnets_str(self):
     port_settings = PortConfig(name='foo', network_name='bar')
     settings = RouterConfig(
         name='foo', project_name='bar', external_gateway='foo_gateway',
         admin_state_up=True, enable_snat=False,
         internal_subnets=['10.0.0.1/24'], interfaces=[port_settings])
     self.assertEqual('foo', settings.name)
     self.assertEqual('bar', settings.project_name)
     self.assertEqual('foo_gateway', settings.external_gateway)
     self.assertTrue(settings.admin_state_up)
     self.assertFalse(settings.enable_snat)
     self.assertIsNotNone(settings.internal_subnets)
     self.assertTrue(isinstance(settings.internal_subnets, list))
     self.assertEqual(1, len(settings.internal_subnets))
     self.assertEqual(['10.0.0.1/24'], settings.internal_subnets)
     self.assertEqual([port_settings], settings.port_settings)
Пример #10
0
 def test_name_flavor_port_only(self):
     port_settings = PortConfig(name='foo-port', network_name='bar-net')
     settings = VmInstanceConfig(name='foo',
                                 flavor='bar',
                                 port_settings=[port_settings])
     self.assertEqual('foo', settings.name)
     self.assertEqual('bar', settings.flavor)
     self.assertEqual(1, len(settings.port_settings))
     self.assertEqual('foo-port', settings.port_settings[0].name)
     self.assertEqual('bar-net', settings.port_settings[0].network_name)
     self.assertEqual(0, len(settings.security_group_names))
     self.assertEqual(0, len(settings.floating_ip_settings))
     self.assertIsNone(settings.sudo_user)
     self.assertEqual(900, settings.vm_boot_timeout)
     self.assertEqual(300, settings.vm_delete_timeout)
     self.assertEqual(180, settings.ssh_connect_timeout)
     self.assertEqual(300, settings.cloud_init_timeout)
     self.assertIsNone(settings.availability_zone)
     self.assertIsNone(settings.volume_names)
Пример #11
0
 def test_vping_userdata(self, deploy_vm, path_exists, create_flavor,
                         get_port_ip, vm_active):
     with mock.patch('snaps.openstack.utils.deploy_utils.create_image',
                     return_value=OpenStackImage(self.os_creds, None)), \
             mock.patch('snaps.openstack.utils.deploy_utils.create_network',
                        return_value=OpenStackNetwork(
                            self.os_creds, NetworkConfig(name='foo'))), \
             mock.patch('snaps.openstack.utils.deploy_utils.'
                        'create_vm_instance',
                        return_value=OpenStackVmInstance(
                            self.os_creds,
                            VmInstanceConfig(
                                name='foo', flavor='bar',
                                port_settings=[PortConfig(
                                    name='foo', network_name='bar')]),
                            None)), \
             mock.patch('snaps.openstack.create_instance.'
                        'OpenStackVmInstance.get_console_output',
                        return_value='vPing OK'):
         self.assertEquals(TestCase.EX_OK, self.vping_userdata.run())
Пример #12
0
 def test_all_internal_subnets_dict(self):
     port_settings = PortConfig(name='foo', network_name='bar')
     int_subs = {'subnet': {
         'project_name': 'proj_a', 'network_name': 'net_name',
         'subnet_name': 'sub_name'}}
     settings = RouterConfig(
         name='foo', project_name='bar', external_gateway='foo_gateway',
         admin_state_up=True, enable_snat=False,
         internal_subnets=int_subs,
         interfaces=[port_settings])
     self.assertEqual('foo', settings.name)
     self.assertEqual('bar', settings.project_name)
     self.assertEqual('foo_gateway', settings.external_gateway)
     self.assertTrue(settings.admin_state_up)
     self.assertFalse(settings.enable_snat)
     self.assertIsNotNone(settings.internal_subnets)
     self.assertTrue(isinstance(settings.internal_subnets, dict))
     self.assertEqual(1, len(settings.internal_subnets))
     self.assertEqual(int_subs, settings.internal_subnets)
     self.assertEqual([port_settings], settings.port_settings)
Пример #13
0
    def create_instance(self, vm_name, flavor_name, image_creator, network,
                        secgrp, av_zone):
        logger.info("Creating the instance {}...".format(vm_name))
        port_settings = PortConfig(name=vm_name + '-port',
                                   network_name=network.name)

        instance_settings = VmInstanceConfig(name=vm_name,
                                             flavor=flavor_name,
                                             security_group_names=str(
                                                 secgrp.name),
                                             port_settings=[port_settings],
                                             availability_zone=av_zone)

        instance_creator = cr_inst.OpenStackVmInstance(
            self.os_creds, instance_settings, image_creator.image_settings)

        instance = instance_creator.create()

        self.creators.append(instance_creator)
        return instance, instance_creator
Пример #14
0
    def test_config_all(self):
        port_settings = PortConfig(name='foo-port', network_name='bar-net')
        fip_settings = FloatingIpConfig(name='foo-fip',
                                        port_name='bar-port',
                                        router_name='foo-bar-router')

        settings = VmInstanceConfig(
            **{
                'name': 'foo',
                'flavor': 'bar',
                'ports': [port_settings],
                'security_group_names': ['sec_grp_1'],
                'floating_ips': [fip_settings],
                'sudo_user': '******',
                'vm_boot_timeout': 999,
                'vm_delete_timeout': 333,
                'ssh_connect_timeout': 111,
                'cloud_init_timeout': 998,
                'availability_zone': 'server name',
                'volume_names': ['vol2']
            })
        self.assertEqual('foo', settings.name)
        self.assertEqual('bar', settings.flavor)
        self.assertEqual(1, len(settings.port_settings))
        self.assertEqual('foo-port', settings.port_settings[0].name)
        self.assertEqual('bar-net', settings.port_settings[0].network_name)
        self.assertEqual(1, len(settings.security_group_names))
        self.assertEqual(1, len(settings.floating_ip_settings))
        self.assertEqual('foo-fip', settings.floating_ip_settings[0].name)
        self.assertEqual('bar-port',
                         settings.floating_ip_settings[0].port_name)
        self.assertEqual('foo-bar-router',
                         settings.floating_ip_settings[0].router_name)
        self.assertEqual('joe', settings.sudo_user)
        self.assertEqual(999, settings.vm_boot_timeout)
        self.assertEqual(333, settings.vm_delete_timeout)
        self.assertEqual(111, settings.ssh_connect_timeout)
        self.assertEqual(998, settings.cloud_init_timeout)
        self.assertEqual('server name', settings.availability_zone)
        self.assertEqual('vol2', settings.volume_names[0])
Пример #15
0
    def test_all(self):
        port_settings = PortConfig(name='foo-port', network_name='bar-net')
        fip_settings = FloatingIpConfig(name='foo-fip',
                                        port_name='bar-port',
                                        router_name='foo-bar-router')

        settings = VmInstanceConfig(name='foo',
                                    flavor='bar',
                                    port_settings=[port_settings],
                                    security_group_names=['sec_grp_1'],
                                    floating_ip_settings=[fip_settings],
                                    sudo_user='******',
                                    vm_boot_timeout=999,
                                    vm_delete_timeout=333,
                                    ssh_connect_timeout=111,
                                    cloud_init_timeout=998,
                                    availability_zone='server name',
                                    volume_names=['vol1'])
        self.assertEqual('foo', settings.name)
        self.assertEqual('bar', settings.flavor)
        self.assertEqual(1, len(settings.port_settings))
        self.assertEqual('foo-port', settings.port_settings[0].name)
        self.assertEqual('bar-net', settings.port_settings[0].network_name)
        self.assertEqual(1, len(settings.security_group_names))
        self.assertEqual('sec_grp_1', settings.security_group_names[0])
        self.assertEqual(1, len(settings.floating_ip_settings))
        self.assertEqual('foo-fip', settings.floating_ip_settings[0].name)
        self.assertEqual('bar-port',
                         settings.floating_ip_settings[0].port_name)
        self.assertEqual('foo-bar-router',
                         settings.floating_ip_settings[0].router_name)
        self.assertEqual('joe', settings.sudo_user)
        self.assertEqual(999, settings.vm_boot_timeout)
        self.assertEqual(333, settings.vm_delete_timeout)
        self.assertEqual(111, settings.ssh_connect_timeout)
        self.assertEqual(998, settings.cloud_init_timeout)
        self.assertEqual('server name', settings.availability_zone)
        self.assertEqual('vol1', settings.volume_names[0])
Пример #16
0
 def test_vping_userdata(self, *args):
     # pylint: disable=unused-argument
     with mock.patch('snaps.openstack.utils.deploy_utils.create_image',
                     return_value=OpenStackImage(self.os_creds, None)), \
             mock.patch('snaps.openstack.utils.deploy_utils.create_network',
                        return_value=OpenStackNetwork(
                            self.os_creds, NetworkConfig(name='foo'))), \
             mock.patch('snaps.openstack.utils.deploy_utils.create_router',
                        return_value=OpenStackRouter(
                            self.os_creds, RouterConfig(name='foo'))), \
             mock.patch('snaps.openstack.utils.deploy_utils.'
                        'create_vm_instance',
                        return_value=OpenStackVmInstance(
                            self.os_creds,
                            VmInstanceConfig(
                                name='foo', flavor='bar',
                                port_settings=[PortConfig(
                                    name='foo', network_name='bar')]),
                            None)), \
             mock.patch('snaps.openstack.create_instance.'
                        'OpenStackVmInstance.get_console_output',
                        return_value='vPing OK'):
         self.assertEquals(TestCase.EX_OK, self.vping_userdata.run())
Пример #17
0
 def test_config_all_internal_subnets_str(self):
     int_subs = {'subnet': {
         'project_name': 'proj_a', 'network_name': 'net_name',
         'subnet_name': 'sub_name'}}
     settings = RouterConfig(
         **{'name': 'foo', 'project_name': 'bar',
            'external_gateway': 'foo_gateway', 'admin_state_up': True,
            'enable_snat': False,
            'internal_subnets': int_subs,
            'interfaces':
                [{'port': {'name': 'foo-port',
                           'network_name': 'bar-net'}}]})
     self.assertEqual('foo', settings.name)
     self.assertEqual('bar', settings.project_name)
     self.assertEqual('foo_gateway', settings.external_gateway)
     self.assertTrue(settings.admin_state_up)
     self.assertFalse(settings.enable_snat)
     self.assertIsNotNone(settings.internal_subnets)
     self.assertTrue(isinstance(settings.internal_subnets, dict))
     self.assertEqual(1, len(settings.internal_subnets))
     self.assertEqual(int_subs, settings.internal_subnets)
     self.assertEqual([PortConfig(**{'name': 'foo-port',
                                     'network_name': 'bar-net'})],
                      settings.port_settings)
Пример #18
0
    def test_vnf(self):
        """Run IXIA Stress test on clearwater ims instance."""
        start_time = time.time()

        cfy_client = self.orchestrator['object']

        outputs = cfy_client.deployments.outputs.get(
            self.vnf['descriptor'].get('name'))['outputs']
        dns_ip = outputs['dns_ip']
        ellis_ip = outputs['ellis_ip']

        self.__logger.info("Creating full IXIA network ...")
        subnet_settings = SubnetConfig(name='ixia_management_subnet',
                                       cidr='10.10.10.0/24',
                                       dns_nameservers=[env.get('NAMESERVER')])
        network_settings = NetworkConfig(name='ixia_management_network',
                                         subnet_settings=[subnet_settings])
        network_creator = OpenStackNetwork(self.snaps_creds, network_settings)
        network_creator.create()
        self.created_object.append(network_creator)
        ext_net_name = snaps_utils.get_ext_net_name(self.snaps_creds)
        router_creator = OpenStackRouter(
            self.snaps_creds,
            RouterConfig(name='ixia_management_router',
                         external_gateway=ext_net_name,
                         internal_subnets=[subnet_settings.name]))
        router_creator.create()
        self.created_object.append(router_creator)

        # security group creation
        self.__logger.info("Creating security groups for IXIA VMs")
        sg_rules = list()
        sg_rules.append(
            SecurityGroupRuleConfig(sec_grp_name="ixia_management",
                                    direction=Direction.ingress,
                                    protocol=Protocol.tcp,
                                    port_range_min=1,
                                    port_range_max=65535))
        sg_rules.append(
            SecurityGroupRuleConfig(sec_grp_name="ixia_management",
                                    direction=Direction.ingress,
                                    protocol=Protocol.udp,
                                    port_range_min=1,
                                    port_range_max=65535))
        sg_rules.append(
            SecurityGroupRuleConfig(sec_grp_name="ixia_management",
                                    direction=Direction.ingress,
                                    protocol=Protocol.icmp))

        ixia_managment_sg_settings = SecurityGroupConfig(
            name="ixia_management", rule_settings=sg_rules)
        securit_group_creator = OpenStackSecurityGroup(
            self.snaps_creds, ixia_managment_sg_settings)

        securit_group_creator.create()
        self.created_object.append(securit_group_creator)

        sg_rules = list()
        sg_rules.append(
            SecurityGroupRuleConfig(sec_grp_name="ixia_ssh_http",
                                    direction=Direction.ingress,
                                    protocol=Protocol.tcp,
                                    port_range_min=1,
                                    port_range_max=65535))

        ixia_ssh_http_sg_settings = SecurityGroupConfig(name="ixia_ssh_http",
                                                        rule_settings=sg_rules)
        securit_group_creator = OpenStackSecurityGroup(
            self.snaps_creds, ixia_ssh_http_sg_settings)

        securit_group_creator.create()
        self.created_object.append(securit_group_creator)

        chassis_flavor_settings = FlavorConfig(name="ixia_vChassis",
                                               ram=4096,
                                               disk=40,
                                               vcpus=2)
        flavor_creator = OpenStackFlavor(self.snaps_creds,
                                         chassis_flavor_settings)
        flavor_creator.create()
        self.created_object.append(flavor_creator)

        card_flavor_settings = FlavorConfig(name="ixia_vCard",
                                            ram=4096,
                                            disk=4,
                                            vcpus=2)
        flavor_creator = OpenStackFlavor(self.snaps_creds,
                                         card_flavor_settings)
        flavor_creator.create()
        self.created_object.append(flavor_creator)

        load_flavor_settings = FlavorConfig(name="ixia_vLoad",
                                            ram=8192,
                                            disk=100,
                                            vcpus=4)
        flavor_creator = OpenStackFlavor(self.snaps_creds,
                                         load_flavor_settings)
        flavor_creator.create()
        self.created_object.append(flavor_creator)

        chassis_image_settings = ImageConfig(
            name=self.test['requirements']['chassis']['image'],
            image_user='******',
            exists=True)

        card_image_settings = ImageConfig(
            name=self.test['requirements']['card']['image'],
            image_user='******',
            exists=True)

        load_image_settings = ImageConfig(
            name=self.test['requirements']['load']['image'],
            image_user='******',
            exists=True)

        chassis_port_settings = PortConfig(name='ixia_chassis_port',
                                           network_name=network_settings.name)

        card1_port1_settings = PortConfig(name='ixia_card1_port1',
                                          network_name=network_settings.name)

        card2_port1_settings = PortConfig(name='ixia_card2_port1',
                                          network_name=network_settings.name)

        card1_port2_settings = PortConfig(name='ixia_card1_port2',
                                          network_name="cloudify_ims_network")

        card2_port2_settings = PortConfig(name='ixia_card2_port2',
                                          network_name="cloudify_ims_network")

        load_port_settings = PortConfig(name='ixia_load_port',
                                        network_name=network_settings.name)

        chassis_settings = VmInstanceConfig(
            name='ixia_vChassis',
            flavor=chassis_flavor_settings.name,
            port_settings=[chassis_port_settings],
            security_group_names=[
                ixia_ssh_http_sg_settings.name, ixia_managment_sg_settings.name
            ],
            floating_ip_settings=[
                FloatingIpConfig(
                    name='ixia_vChassis_fip',
                    port_name=chassis_port_settings.name,
                    router_name=router_creator.router_settings.name)
            ])

        vm_creator = OpenStackVmInstance(self.snaps_creds, chassis_settings,
                                         chassis_image_settings)

        self.__logger.info("Creating Ixia vChassis VM")
        vm_creator.create()
        fip_chassis = vm_creator.get_floating_ip().ip
        self.created_object.append(vm_creator)

        card1_settings = VmInstanceConfig(
            name='ixia_vCard1',
            flavor=card_flavor_settings.name,
            port_settings=[card1_port1_settings, card1_port2_settings],
            security_group_names=[ixia_managment_sg_settings.name])

        vm_creator = OpenStackVmInstance(self.snaps_creds, card1_settings,
                                         card_image_settings)

        self.__logger.info("Creating Ixia vCard1 VM")
        vm_creator.create()
        vcard_ips = list()
        vcard_ips_p2 = list()
        vcard_ips.append(vm_creator.get_port_ip('ixia_card1_port1'))
        vcard_ips_p2.append(vm_creator.get_port_ip('ixia_card1_port2'))
        self.created_object.append(vm_creator)

        card2_settings = VmInstanceConfig(
            name='ixia_vCard2',
            flavor=card_flavor_settings.name,
            port_settings=[card2_port1_settings, card2_port2_settings],
            security_group_names=[ixia_managment_sg_settings.name])

        vm_creator = OpenStackVmInstance(self.snaps_creds, card2_settings,
                                         card_image_settings)

        self.__logger.info("Creating Ixia vCard2 VM")
        vm_creator.create()
        vcard_ips.append(vm_creator.get_port_ip('ixia_card2_port1'))
        vcard_ips_p2.append(vm_creator.get_port_ip('ixia_card2_port2'))
        self.created_object.append(vm_creator)

        load_settings = VmInstanceConfig(
            name='ixia_vLoad',
            flavor=load_flavor_settings.name,
            port_settings=[load_port_settings],
            security_group_names=[
                ixia_ssh_http_sg_settings.name, ixia_managment_sg_settings.name
            ],
            floating_ip_settings=[
                FloatingIpConfig(
                    name='ixia_vLoad_fip',
                    port_name=load_port_settings.name,
                    router_name=router_creator.router_settings.name)
            ])

        vm_creator = OpenStackVmInstance(self.snaps_creds, load_settings,
                                         load_image_settings)

        self.__logger.info("Creating Ixia vLoad VM")
        vm_creator.create()
        fip_load = vm_creator.get_floating_ip().ip
        self.created_object.append(vm_creator)

        self.__logger.info("Chassis IP is: %s", fip_chassis)
        login_url = "https://" + str(fip_chassis) + "/api/v1/auth/session"
        cards_url = "https://" + str(fip_chassis) + "/api/v2/ixos/cards/"

        payload = json.dumps({
            "username": "******",
            "password": "******",
            "rememberMe": "false"
        })
        api_key = json.loads(
            (IxChassisUtils.ChassisRestAPI.postWithPayload(login_url,
                                                           payload)))["apiKey"]

        self.__logger.info("Adding 2 card back inside the ixia chassis...")

        for ip in vcard_ips:
            payload = {"ipAddress": str(ip)}
            response = json.loads(
                IxChassisUtils.ChassisRestAPI.postOperation(
                    cards_url, api_key, payload))
            count = 0
            while (int(
                    IxChassisUtils.ChassisRestAPI.getWithHeaders(
                        response['url'], api_key)['progress']) != 100):
                self.__logger.debug("Operation did not finish yet. \
                                    Waiting for 1 more second..")
                time.sleep(1)
                if count > 60:
                    raise Exception("Adding card take more than 60 seconds")
                count += 1

        ssh = paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.MissingHostKeyPolicy())
        ssh.connect(fip_chassis, username="******", password="******")
        cmd = "set license-check disable"
        run_blocking_ssh_command(ssh, cmd)
        cmd = "restart-service ixServer"
        run_blocking_ssh_command(ssh, cmd)

        self.config_ellis(ellis_ip)

        # Get IPs of P-CSCF
        resolver = dns.resolver.Resolver()
        resolver.nameservers = [dns_ip]
        result = resolver.query("bono.clearwater.local")

        iplistims = ''
        i = 0
        for rdata in result:
            i = i + 1
            print rdata.address
            iplistims += str(rdata.address)
            if i != len(result):
                iplistims += ';'

        kResourcesUrl = 'http://%s:%s/api/v0/resources' % (fip_load, 8080)

        kRxfPath = r"REG_CALL_OPNFV_v13.rxf"
        test_filname = self.test['inputs']['test_filname']
        kGatewaySharedFolder = '/mnt/ixload-share/'
        kRxfRelativeUploadPath = 'uploads/%s' % os.path.split(kRxfPath)[1]
        kRxfAbsoluteUploadPath = os.path.join(kGatewaySharedFolder,
                                              kRxfRelativeUploadPath)
        kChassisList = [str(fip_chassis)]
        dataFileNameList = [
            test_filname, 'Registration_only_LPS.tst', 'SIPCall.tst'
        ]

        kPortListPerCommunityCommunity = {
            "VoIP1@VM1": [(1, 1, 1)],
            "VoIP2@VM2": [(1, 2, 1)]
        }

        kStatsToDisplayDict = self.test['inputs']['stats']
        connection = IxRestUtils.getConnection(fip_load, 8080)

        self.__logger.info("Creating a new session...")
        sessionUrl = IxLoadUtils.createSession(connection,
                                               self.test['version'])

        license_server = self.test['inputs']['licenseServer']
        IxLoadUtils.configureLicenseServer(connection, sessionUrl,
                                           license_server)

        files_dir = os.path.join(self.case_dir, 'ixia/files')
        target_file = open(os.path.join(files_dir, test_filname), 'w')
        j2_env = Environment(loader=FileSystemLoader(files_dir),
                             trim_blocks=True)
        self.test['inputs'].update(
            dict(ipchassis=fip_chassis,
                 ipcard1=vcard_ips_p2[0],
                 ipcard2=vcard_ips_p2[1],
                 iplistims=iplistims))

        target_file.write(
            j2_env.get_template(test_filname + '.template').render(
                self.test['inputs']))
        target_file.close()

        self.__logger.info('Uploading files %s...' % kRxfPath)
        for dataFile in dataFileNameList:
            localFilePath = os.path.join(files_dir, dataFile)
            remoteFilePath = os.path.join(kGatewaySharedFolder,
                                          'uploads/%s' % dataFile)
            IxLoadUtils.uploadFile(connection, kResourcesUrl, localFilePath,
                                   remoteFilePath)
        self.__logger.info('Upload file finished.')

        self.__logger.info("Loading repository %s..." % kRxfAbsoluteUploadPath)
        IxLoadUtils.loadRepository(connection, sessionUrl,
                                   kRxfAbsoluteUploadPath)

        self.__logger.info("Clearing chassis list...")
        IxLoadUtils.clearChassisList(connection, sessionUrl)

        self.__logger.info("Adding chassis %s..." % (kChassisList))
        IxLoadUtils.addChassisList(connection, sessionUrl, kChassisList)

        self.__logger.info("Assigning new ports...")
        IxLoadUtils.assignPorts(connection, sessionUrl,
                                kPortListPerCommunityCommunity)

        self.__logger.info("Starting the test...")
        IxLoadUtils.runTest(connection, sessionUrl)

        self.__logger.info("Polling values for stats %s..." %
                           (kStatsToDisplayDict))
        result = IxLoadUtils.pollStats(connection, sessionUrl,
                                       kStatsToDisplayDict)
        self.__logger.info("Test finished.")
        self.__logger.info("Checking test status...")
        testRunError = IxLoadUtils.getTestRunError(connection, sessionUrl)

        self.__logger.info(result)
        duration = time.time() - start_time
        self.details['test_vnf'].update(status='PASS',
                                        result=result,
                                        duration=duration)
        if testRunError:
            self.__logger.info("The test exited with following error: %s" %
                               (testRunError))
            self.details['test_vnf'].update(status='FAIL', duration=duration)
            return False
        else:
            self.__logger.info("The test completed successfully.")
            self.details['test_vnf'].update(status='PASS', duration=duration)
            self.result += 1 / 3 * 100
            return True
Пример #19
0
    def deploy_orchestrator(self):
        self.logger.info("Deploying Open Baton...")
        self.logger.info("Details: %s", self.mano['details'])
        start_time = time.time()

        self.logger.info("Creating orchestra instance...")
        userdata = get_userdata(self.mano)
        self.logger.info("flavor: %s\n"
                         "image: %s\n"
                         "network_id: %s\n",
                         self.mano['details']['flavor']['name'],
                         self.mano['requirements']['image'],
                         self.mano['details']['network']['id'])
        self.logger.debug("userdata: %s\n", userdata)
        # setting up image
        image_settings = ImageConfig(name=self.mano['requirements']['image'],
                                     image_user='******',
                                     exists=True)
        # setting up port
        port_settings = PortConfig(
            name='%s_port' % self.case_name,
            network_name=self.mano['details']['network']['name'])
        # build configuration of vm
        orchestra_settings = VmInstanceConfig(
            name=self.case_name,
            flavor=self.mano['details']['flavor']['name'],
            port_settings=[port_settings],
            security_group_names=[self.mano['details']['sec_group']],
            userdata=str(userdata))
        orchestra_vm = OpenStackVmInstance(self.snaps_creds,
                                           orchestra_settings, image_settings)

        orchestra_vm.create()
        self.created_resources.append(orchestra_vm)
        self.mano['details']['id'] = orchestra_vm.get_vm_info()['id']
        self.logger.info("Created orchestra instance: %s",
                         self.mano['details']['id'])

        self.logger.info("Associating floating ip: '%s' to VM '%s' ",
                         self.mano['details']['fip'].ip, self.case_name)
        nova_client = os_utils.get_nova_client()
        if not os_utils.add_floating_ip(nova_client,
                                        self.mano['details']['id'],
                                        self.mano['details']['fip'].ip):
            duration = time.time() - start_time
            self.details["orchestrator"].update(status='FAIL',
                                                duration=duration)
            self.logger.error("Cannot associate floating IP to VM.")
            return False

        self.logger.info("Waiting for Open Baton NFVO to be up and running...")
        timeout = 0
        while timeout < 20:
            if servertest(self.mano['details']['fip'].ip, "8080"):
                break
            else:
                self.logger.info("Open Baton NFVO is not started yet (%ss)",
                                 (timeout * 60))
                time.sleep(60)
                timeout += 1

        if timeout >= 20:
            duration = time.time() - start_time
            self.details["orchestrator"].update(status='FAIL',
                                                duration=duration)
            self.logger.error("Open Baton is not started correctly")
            return False

        self.logger.info("Waiting for all components to be up and running...")
        time.sleep(60)
        duration = time.time() - start_time
        self.details["orchestrator"].update(status='PASS', duration=duration)
        self.logger.info("Deploy Open Baton NFVO: OK")
        return True
Пример #20
0
    def setUp(self):
        """
        Instantiates the CreateImage object that is responsible for downloading
        and creating an OS image file within OpenStack
        """
        super(self.__class__, self).__start__()

        self.nova = nova_utils.nova_client(self.os_creds, self.os_session)

        guid = self.__class__.__name__ + '-' + str(uuid.uuid4())
        self.keypair_priv_filepath = 'tmp/' + guid
        self.keypair_pub_filepath = self.keypair_priv_filepath + '.pub'
        self.keypair_name = guid + '-kp'
        self.vm_inst_name = guid + '-inst'
        self.test_file_local_path = 'tmp/' + guid + '-hello.txt'
        self.port_1_name = guid + '-port-1'
        self.port_2_name = guid + '-port-2'
        self.floating_ip_name = guid + 'fip1'

        # Setup members to cleanup just in case they don't get created
        self.inst_creator = None
        self.keypair_creator = None
        self.sec_grp_creator = None
        self.flavor_creator = None
        self.router_creator = None
        self.network_creator = None
        self.image_creator = None

        try:
            # Create Image
            os_image_settings = openstack_tests.ubuntu_image_settings(
                name=guid + '-' + '-image', image_metadata=self.image_metadata)
            self.image_creator = create_image.OpenStackImage(
                self.os_creds, os_image_settings)
            self.image_creator.create()

            # First network is public
            self.pub_net_config = openstack_tests.get_pub_net_config(
                project_name=self.os_creds.project_name,
                net_name=guid + '-pub-net',
                mtu=1442,
                subnet_name=guid + '-pub-subnet',
                router_name=guid + '-pub-router',
                external_net=self.ext_net_name)

            self.network_creator = create_network.OpenStackNetwork(
                self.os_creds, self.pub_net_config.network_settings)
            self.network_creator.create()

            # Create routers
            self.router_creator = create_router.OpenStackRouter(
                self.os_creds, self.pub_net_config.router_settings)
            self.router_creator.create()

            # Create Flavor
            flavor_config = openstack_tests.get_flavor_config(
                name=guid + '-flavor-name',
                ram=2048,
                disk=10,
                vcpus=2,
                metadata=self.flavor_metadata)

            self.flavor_creator = create_flavor.OpenStackFlavor(
                self.admin_os_creds, flavor_config)
            self.flavor_creator.create()

            # Create Key/Pair
            self.keypair_creator = create_keypairs.OpenStackKeypair(
                self.os_creds,
                KeypairConfig(name=self.keypair_name,
                              public_filepath=self.keypair_pub_filepath,
                              private_filepath=self.keypair_priv_filepath))
            self.keypair_creator.create()

            # Create Security Group
            sec_grp_name = guid + '-sec-grp'
            rule1 = SecurityGroupRuleConfig(sec_grp_name=sec_grp_name,
                                            direction=Direction.ingress,
                                            protocol=Protocol.icmp)
            rule2 = SecurityGroupRuleConfig(sec_grp_name=sec_grp_name,
                                            direction=Direction.ingress,
                                            protocol=Protocol.tcp,
                                            port_range_min=22,
                                            port_range_max=22)
            self.sec_grp_creator = OpenStackSecurityGroup(
                self.os_creds,
                SecurityGroupConfig(name=sec_grp_name,
                                    rule_settings=[rule1, rule2]))
            self.sec_grp_creator.create()

            # Create instance
            ports_settings = list()
            ports_settings.append(
                PortConfig(
                    name=self.port_1_name,
                    network_name=self.pub_net_config.network_settings.name))

            instance_settings = VmInstanceConfig(
                name=self.vm_inst_name,
                flavor=self.flavor_creator.flavor_settings.name,
                port_settings=ports_settings,
                floating_ip_settings=[
                    FloatingIpConfig(
                        name=self.floating_ip_name,
                        port_name=self.port_1_name,
                        router_name=self.pub_net_config.router_settings.name)
                ])

            self.inst_creator = create_instance.OpenStackVmInstance(
                self.os_creds,
                instance_settings,
                self.image_creator.image_settings,
                keypair_settings=self.keypair_creator.keypair_settings)
        except:
            self.tearDown()
            raise
Пример #21
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,
                KeypairConfig(name=self.kp_name,
                              private_filepath=self.kp_priv_file,
                              public_filepath=self.kp_pub_file))
            self.creators.append(kp_creator)

            # Creating Instance 1
            port1_settings = PortConfig(
                name=self.vm1_name + '-vPingPort',
                network_name=self.network_creator.network_settings.name)
            instance1_settings = VmInstanceConfig(
                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 = PortConfig(
                name=self.vm2_name + '-vPingPort',
                network_name=self.network_creator.network_settings.name)
            instance2_settings = VmInstanceConfig(
                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=[
                    FloatingIpConfig(
                        name=self.vm2_name + '-FIPName',
                        port_name=port2_settings.name,
                        router_name=self.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()
Пример #22
0
    def deploy_orchestrator(self):
        """
        Deploy Cloudify Manager.

        network, security group, fip, VM creation
        """
        # network creation

        start_time = time.time()
        self.__logger.info("Creating keypair ...")
        kp_file = os.path.join(self.data_dir, "cloudify_ims.pem")
        keypair_settings = KeypairConfig(name='cloudify_ims_kp',
                                         private_filepath=kp_file)
        keypair_creator = OpenStackKeypair(self.snaps_creds, keypair_settings)
        keypair_creator.create()
        self.created_object.append(keypair_creator)

        self.__logger.info("Creating full network ...")
        subnet_settings = SubnetConfig(name='cloudify_ims_subnet',
                                       cidr='10.67.79.0/24')
        network_settings = NetworkConfig(name='cloudify_ims_network',
                                         subnet_settings=[subnet_settings])
        network_creator = OpenStackNetwork(self.snaps_creds, network_settings)
        network_creator.create()
        self.created_object.append(network_creator)
        ext_net_name = snaps_utils.get_ext_net_name(self.snaps_creds)
        router_creator = OpenStackRouter(
            self.snaps_creds,
            RouterConfig(name='cloudify_ims_router',
                         external_gateway=ext_net_name,
                         internal_subnets=[subnet_settings.name]))
        router_creator.create()
        self.created_object.append(router_creator)

        # security group creation
        self.__logger.info("Creating security group for cloudify manager vm")
        sg_rules = list()
        sg_rules.append(
            SecurityGroupRuleConfig(sec_grp_name="sg-cloudify-manager",
                                    direction=Direction.ingress,
                                    protocol=Protocol.tcp,
                                    port_range_min=1,
                                    port_range_max=65535))
        sg_rules.append(
            SecurityGroupRuleConfig(sec_grp_name="sg-cloudify-manager",
                                    direction=Direction.ingress,
                                    protocol=Protocol.udp,
                                    port_range_min=1,
                                    port_range_max=65535))

        securit_group_creator = OpenStackSecurityGroup(
            self.snaps_creds,
            SecurityGroupConfig(name="sg-cloudify-manager",
                                rule_settings=sg_rules))

        securit_group_creator.create()
        self.created_object.append(securit_group_creator)

        # orchestrator VM flavor
        self.__logger.info("Get or create flavor for cloudify manager vm ...")

        flavor_settings = FlavorConfig(
            name=self.orchestrator['requirements']['flavor']['name'],
            ram=self.orchestrator['requirements']['flavor']['ram_min'],
            disk=50,
            vcpus=2)
        flavor_creator = OpenStackFlavor(self.snaps_creds, flavor_settings)
        flavor_creator.create()
        self.created_object.append(flavor_creator)
        image_settings = ImageConfig(
            name=self.orchestrator['requirements']['os_image'],
            image_user='******',
            exists=True)

        port_settings = PortConfig(name='cloudify_manager_port',
                                   network_name=network_settings.name)

        manager_settings = VmInstanceConfig(
            name='cloudify_manager',
            flavor=flavor_settings.name,
            port_settings=[port_settings],
            security_group_names=[securit_group_creator.sec_grp_settings.name],
            floating_ip_settings=[
                FloatingIpConfig(
                    name='cloudify_manager_fip',
                    port_name=port_settings.name,
                    router_name=router_creator.router_settings.name)
            ])

        manager_creator = OpenStackVmInstance(self.snaps_creds,
                                              manager_settings, image_settings,
                                              keypair_settings)

        self.__logger.info("Creating cloudify manager VM")
        manager_creator.create()
        self.created_object.append(manager_creator)

        public_auth_url = keystone_utils.get_endpoint(self.snaps_creds,
                                                      'identity')

        self.__logger.info("Set creds for cloudify manager")
        cfy_creds = dict(keystone_username=self.snaps_creds.username,
                         keystone_password=self.snaps_creds.password,
                         keystone_tenant_name=self.snaps_creds.project_name,
                         keystone_url=public_auth_url)

        cfy_client = CloudifyClient(host=manager_creator.get_floating_ip().ip,
                                    username='******',
                                    password='******',
                                    tenant='default_tenant')

        self.orchestrator['object'] = cfy_client

        self.__logger.info("Attemps running status of the Manager")
        cfy_status = None
        retry = 10
        while str(cfy_status) != 'running' and retry:
            try:
                cfy_status = cfy_client.manager.get_status()['status']
                self.__logger.debug("The current manager status is %s",
                                    cfy_status)
            except Exception:  # pylint: disable=broad-except
                self.__logger.warning("Cloudify Manager isn't " +
                                      "up and running. Retrying ...")
            retry = retry - 1
            time.sleep(30)

        if str(cfy_status) == 'running':
            self.__logger.info("Cloudify Manager is up and running")
        else:
            raise Exception("Cloudify Manager isn't up and running")

        self.__logger.info("Put OpenStack creds in manager")
        secrets_list = cfy_client.secrets.list()
        for k, val in cfy_creds.iteritems():
            if not any(d.get('key', None) == k for d in secrets_list):
                cfy_client.secrets.create(k, val)
            else:
                cfy_client.secrets.update(k, val)

        duration = time.time() - start_time

        self.__logger.info("Put private keypair in manager")
        if manager_creator.vm_ssh_active(block=True):
            ssh = manager_creator.ssh_client()
            scp = SCPClient(ssh.get_transport(), socket_timeout=15.0)
            scp.put(kp_file, '~/')
            cmd = "sudo cp ~/cloudify_ims.pem /etc/cloudify/"
            run_blocking_ssh_command(ssh, cmd)
            cmd = "sudo chmod 444 /etc/cloudify/cloudify_ims.pem"
            run_blocking_ssh_command(ssh, cmd)
            cmd = "sudo yum install -y gcc python-devel"
            run_blocking_ssh_command(
                ssh, cmd, "Unable to install packages \
                                                on manager")

        self.details['orchestrator'].update(status='PASS', duration=duration)

        self.vnf['inputs'].update(
            dict(external_network_name=ext_net_name,
                 network_name=network_settings.name))
        self.result = 1 / 3 * 100
        return True
Пример #23
0
    def __init__(self, **kwargs):
        """
        Constructor
        :param name: the name of the VM
        :param flavor: the VM's flavor name
        :param port_settings: the port configuration settings (required)
        :param security_group_names: a set of names of the security groups to
                                     add to the VM
        :param floating_ip_settings: the floating IP configuration settings
        :param sudo_user: the sudo user of the VM that will override the
                          instance_settings.image_user when trying to
                          connect to the VM
        :param vm_boot_timeout: the amount of time a thread will wait
                                for an instance to boot
        :param vm_delete_timeout: the amount of time a thread will wait
                                  for an instance to be deleted
        :param ssh_connect_timeout: the amount of time a thread will wait
                                    to obtain an SSH connection to a VM
        :param cloud_init_timeout: the amount of time a thread will wait for
                                   cloud-init to complete
        :param availability_zone: the name of the compute server on which to
                                  deploy the VM (optional)
        :param volume_names: a list of the names of the volume to attach
                             (optional)
        :param userdata: the string contents of any optional cloud-init script
                         to execute after the VM has been activated.
                         This value may also contain a dict who's key value
                         must contain the key 'cloud-init_file' which denotes
                         the location of some file containing the cloud-init
                         script
        """
        self.name = kwargs.get('name')
        self.flavor = kwargs.get('flavor')
        self.sudo_user = kwargs.get('sudo_user')
        self.userdata = kwargs.get('userdata')

        self.port_settings = list()
        port_settings = kwargs.get('ports')
        if not port_settings:
            port_settings = kwargs.get('port_settings')
        if port_settings:
            for port_setting in port_settings:
                if isinstance(port_setting, dict):
                    self.port_settings.append(PortConfig(**port_setting))
                elif isinstance(port_setting, PortConfig):
                    self.port_settings.append(port_setting)

        if kwargs.get('security_group_names'):
            if isinstance(kwargs['security_group_names'], list):
                self.security_group_names = kwargs['security_group_names']
            elif isinstance(kwargs['security_group_names'], set):
                self.security_group_names = kwargs['security_group_names']
            elif isinstance(kwargs['security_group_names'], str):
                self.security_group_names = [kwargs['security_group_names']]
            else:
                raise VmInstanceConfigError(
                    'Invalid data type for security_group_names attribute')
        else:
            self.security_group_names = set()

        self.floating_ip_settings = list()
        floating_ip_settings = kwargs.get('floating_ips')
        if not floating_ip_settings:
            floating_ip_settings = kwargs.get('floating_ip_settings')
        if floating_ip_settings:
            for floating_ip_config in floating_ip_settings:
                if isinstance(floating_ip_config, FloatingIpConfig):
                    self.floating_ip_settings.append(floating_ip_config)
                else:
                    self.floating_ip_settings.append(FloatingIpConfig(
                        **floating_ip_config['floating_ip']))

        self.vm_boot_timeout = kwargs.get('vm_boot_timeout', 900)
        self.vm_delete_timeout = kwargs.get('vm_delete_timeout', 300)
        self.ssh_connect_timeout = kwargs.get('ssh_connect_timeout', 180)
        self.cloud_init_timeout = kwargs.get('cloud_init_timeout', 300)
        self.availability_zone = kwargs.get('availability_zone')
        self.volume_names = kwargs.get('volume_names')

        if self.volume_names and not isinstance(self.volume_names, list):
            raise VmInstanceConfigError('volume_names must be a list')

        if not self.name or not self.flavor:
            raise VmInstanceConfigError(
                'Instance configuration requires the attributes: name, flavor')

        if len(self.port_settings) == 0:
            raise VmInstanceConfigError(
                'Instance configuration requires port settings (aka. NICS)')
Пример #24
0
    def deploy_orchestrator(self):
        # pylint: disable=too-many-locals,too-many-statements
        """
        Deploy Cloudify Manager.

        network, security group, fip, VM creation
        """
        start_time = time.time()

        # orchestrator VM flavor
        self.__logger.info("Get or create flavor for cloudify manager vm ...")
        flavor_settings = FlavorConfig(
            name="{}-{}".format(
                self.orchestrator['requirements']['flavor']['name'],
                self.uuid),
            ram=self.orchestrator['requirements']['flavor']['ram_min'],
            disk=50,
            vcpus=2)
        flavor_creator = OpenStackFlavor(self.snaps_creds, flavor_settings)
        flavor_creator.create()
        self.created_object.append(flavor_creator)

        self.__logger.info("Creating a second user to bypass issues ...")
        user_creator = OpenStackUser(
            self.snaps_creds,
            UserConfig(
                name='cloudify_network_bug-{}'.format(self.uuid),
                password=str(uuid.uuid4()),
                project_name=self.tenant_name,
                domain_name=self.snaps_creds.user_domain_name,
                roles={'_member_': self.tenant_name}))
        user_creator.create()
        self.created_object.append(user_creator)

        snaps_creds = user_creator.get_os_creds(self.snaps_creds.project_name)
        self.__logger.debug("snaps creds: %s", snaps_creds)

        self.__logger.info("Creating keypair ...")
        kp_file = os.path.join(self.data_dir, "cloudify_ims.pem")
        keypair_settings = KeypairConfig(
            name='cloudify_ims_kp-{}'.format(self.uuid),
            private_filepath=kp_file)
        keypair_creator = OpenStackKeypair(snaps_creds, keypair_settings)
        keypair_creator.create()
        self.created_object.append(keypair_creator)

        # needs some images
        self.__logger.info("Upload some OS images if it doesn't exist")
        for image_name, image_file in self.images.iteritems():
            self.__logger.info("image: %s, file: %s", image_name, image_file)
            if image_file and image_name:
                image_creator = OpenStackImage(
                    snaps_creds,
                    ImageConfig(
                        name=image_name, image_user='******',
                        img_format='qcow2', image_file=image_file))
                image_creator.create()
                self.created_object.append(image_creator)

        # network creation
        self.__logger.info("Creating full network ...")
        subnet_settings = SubnetConfig(
            name='cloudify_ims_subnet-{}'.format(self.uuid),
            cidr='10.67.79.0/24',
            dns_nameservers=[env.get('NAMESERVER')])
        network_settings = NetworkConfig(
            name='cloudify_ims_network-{}'.format(self.uuid),
            subnet_settings=[subnet_settings])
        network_creator = OpenStackNetwork(snaps_creds, network_settings)
        network_creator.create()
        self.created_object.append(network_creator)
        ext_net_name = snaps_utils.get_ext_net_name(snaps_creds)
        router_creator = OpenStackRouter(
            snaps_creds,
            RouterConfig(
                name='cloudify_ims_router-{}'.format(self.uuid),
                external_gateway=ext_net_name,
                internal_subnets=[subnet_settings.name]))
        router_creator.create()
        self.created_object.append(router_creator)

        # security group creation
        self.__logger.info("Creating security group for cloudify manager vm")
        sg_rules = list()
        sg_rules.append(
            SecurityGroupRuleConfig(
                sec_grp_name="sg-cloudify-manager-{}".format(self.uuid),
                direction=Direction.ingress, protocol=Protocol.tcp,
                port_range_min=1, port_range_max=65535))
        sg_rules.append(
            SecurityGroupRuleConfig(
                sec_grp_name="sg-cloudify-manager-{}".format(self.uuid),
                direction=Direction.ingress, protocol=Protocol.udp,
                port_range_min=1, port_range_max=65535))
        security_group_creator = OpenStackSecurityGroup(
            snaps_creds,
            SecurityGroupConfig(
                name="sg-cloudify-manager-{}".format(self.uuid),
                rule_settings=sg_rules))
        security_group_creator.create()
        self.created_object.append(security_group_creator)

        image_settings = ImageConfig(
            name=self.orchestrator['requirements']['os_image'],
            image_user='******',
            exists=True)
        port_settings = PortConfig(
            name='cloudify_manager_port-{}'.format(self.uuid),
            network_name=network_settings.name)
        manager_settings = VmInstanceConfig(
            name='cloudify_manager-{}'.format(self.uuid),
            flavor=flavor_settings.name,
            port_settings=[port_settings],
            security_group_names=[
                security_group_creator.sec_grp_settings.name],
            floating_ip_settings=[FloatingIpConfig(
                name='cloudify_manager_fip-{}'.format(self.uuid),
                port_name=port_settings.name,
                router_name=router_creator.router_settings.name)])
        manager_creator = OpenStackVmInstance(
            snaps_creds, manager_settings, image_settings,
            keypair_settings)
        self.__logger.info("Creating cloudify manager VM")
        manager_creator.create()
        self.created_object.append(manager_creator)

        public_auth_url = keystone_utils.get_endpoint(snaps_creds, 'identity')

        cfy_creds = dict(
            keystone_username=snaps_creds.username,
            keystone_password=snaps_creds.password,
            keystone_tenant_name=snaps_creds.project_name,
            keystone_url=public_auth_url,
            region=snaps_creds.region_name,
            user_domain_name=snaps_creds.user_domain_name,
            project_domain_name=snaps_creds.project_domain_name)
        self.__logger.info("Set creds for cloudify manager %s", cfy_creds)

        cfy_client = CloudifyClient(
            host=manager_creator.get_floating_ip().ip,
            username='******', password='******', tenant='default_tenant')

        self.orchestrator['object'] = cfy_client

        self.__logger.info("Attemps running status of the Manager")
        for loop in range(10):
            try:
                self.__logger.debug(
                    "status %s", cfy_client.manager.get_status())
                cfy_status = cfy_client.manager.get_status()['status']
                self.__logger.info(
                    "The current manager status is %s", cfy_status)
                if str(cfy_status) != 'running':
                    raise Exception("Cloudify Manager isn't up and running")
                self.__logger.info("Put OpenStack creds in manager")
                secrets_list = cfy_client.secrets.list()
                for k, val in cfy_creds.iteritems():
                    if not any(d.get('key', None) == k for d in secrets_list):
                        cfy_client.secrets.create(k, val)
                    else:
                        cfy_client.secrets.update(k, val)
                break
            except Exception:  # pylint: disable=broad-except
                self.logger.info(
                    "try %s: Cloudify Manager isn't up and running", loop + 1)
                time.sleep(30)
        else:
            self.logger.error("Cloudify Manager isn't up and running")
            return False

        duration = time.time() - start_time

        if manager_creator.vm_ssh_active(block=True):
            self.__logger.info("Put private keypair in manager")
            ssh = manager_creator.ssh_client()
            scp = SCPClient(ssh.get_transport(), socket_timeout=15.0)
            scp.put(kp_file, '~/')
            cmd = "sudo cp ~/cloudify_ims.pem /etc/cloudify/"
            self.run_blocking_ssh_command(ssh, cmd)
            cmd = "sudo chmod 444 /etc/cloudify/cloudify_ims.pem"
            self.run_blocking_ssh_command(ssh, cmd)
            # cmd2 is badly unpinned by Cloudify
            cmd = "sudo yum install -y gcc python-devel python-cmd2"
            self.run_blocking_ssh_command(
                ssh, cmd, "Unable to install packages on manager")
            self.run_blocking_ssh_command(ssh, 'cfy status')
        else:
            self.__logger.error("Cannot connect to manager")
            return False

        self.details['orchestrator'].update(status='PASS', duration=duration)

        self.vnf['inputs'].update(dict(
            external_network_name=ext_net_name,
            network_name=network_settings.name,
            key_pair_name=keypair_settings.name
        ))
        self.result = 1/3 * 100
        return True
Пример #25
0
                                 subnet_settings=[subnet_settings])
network = OpenStackNetwork(os_creds, network_settings)
network.create()

# Flavors
from snaps.config.flavor import FlavorConfig
from snaps.openstack.create_flavor import OpenStackFlavor

flavor_settings = FlavorConfig(name='test-flavor', ram=256, disk=10, vcpus=2)
flavor = OpenStackFlavor(os_creds, flavor_settings)
flavor.create()

# Instances
from snaps.config.network import PortConfig
from snaps.openstack.create_instance import OpenStackVmInstance

port_settings = PortConfig(name='test-port',
                           network_name=network_settings.name)
instance_settings = VmInstanceConfig(name='test-inst',
                                     flavor=flavor_settings.name,
                                     port_settings=[port_settings])

vm_inst = OpenStackVmInstance(os_creds, instance_settings, image_settings)
vm_inst.create(block=True)

# Cleanup
vm_inst.clean()
flavor.clean()
network.clean()
image.clean()