def prepare_network(self):
     """Create network/subnet/router if they doen't exist yet"""
     self.logger.info(
         "Creating network/subnet/router if they doen't exist yet...")
     subnet_settings = SubnetConfig(name='%s_subnet' % self.case_name,
                                    cidr="192.168.100.0/24")
     network_settings = NetworkConfig(name='%s_net' % self.case_name,
                                      subnet_settings=[subnet_settings])
     orchestra_network = OpenStackNetwork(self.snaps_creds,
                                          network_settings)
     orchestra_network_info = orchestra_network.create()
     self.mano['details']['network'] = {}
     self.mano['details']['network']['id'] = orchestra_network_info.id
     self.mano['details']['network']['name'] = orchestra_network_info.name
     self.mano['details']['external_net_name'] = \
         snaps_utils.get_ext_net_name(self.snaps_creds)
     self.created_resources.append(orchestra_network)
     orchestra_router = OpenStackRouter(
         self.snaps_creds,
         RouterConfig(
             name='%s_router' % self.case_name,
             external_gateway=self.mano['details']['external_net_name'],
             internal_subnets=[subnet_settings.name]))
     orchestra_router.create()
     self.created_resources.append(orchestra_router)
     self.logger.info("Created network and router for Open Baton NFVO...")
Exemple #2
0
    def create_network_infrastructure(self, net_name, subnet_name, subnet_cidr,
                                      router_name):
        logger.info("Creating networks...")
        # Network and subnet
        subnet_settings = SubnetConfig(name=subnet_name, cidr=subnet_cidr)
        network_settings = NetworkConfig(name=net_name,
                                         subnet_settings=[subnet_settings])
        network_creator = OpenStackNetwork(self.os_creds, network_settings)
        network = network_creator.create()

        self.creators.append(network_creator)

        # Router
        logger.info("Creating the router...")
        ext_network_name = env.get('EXTERNAL_NETWORK')

        router_settings = RouterConfig(name=router_name,
                                       external_gateway=ext_network_name,
                                       internal_subnets=[subnet_name])

        router_creator = OpenStackRouter(self.os_creds, router_settings)
        router = router_creator.create()

        self.creators.append(router_creator)

        return network, router
Exemple #3
0
    def _create_network(self, project_name):
        """Create network for tests."""
        tempest_network_type = None
        tempest_physical_network = None
        tempest_segmentation_id = None

        if hasattr(CONST, 'tempest_network_type'):
            tempest_network_type = CONST.__getattribute__(
                'tempest_network_type')
        if hasattr(CONST, 'tempest_physical_network'):
            tempest_physical_network = CONST.__getattribute__(
                'tempest_physical_network')
        if hasattr(CONST, 'tempest_segmentation_id'):
            tempest_segmentation_id = CONST.__getattribute__(
                'tempest_segmentation_id')

        network_creator = deploy_utils.create_network(
            self.os_creds,
            NetworkConfig(
                name=CONST.__getattribute__('tempest_private_net_name') +
                self.guid,
                project_name=project_name,
                network_type=tempest_network_type,
                physical_network=tempest_physical_network,
                segmentation_id=tempest_segmentation_id,
                subnet_settings=[
                    SubnetConfig(name=CONST.__getattribute__(
                        'tempest_private_subnet_name') + self.guid,
                                 project_name=project_name,
                                 cidr=CONST.__getattribute__(
                                     'tempest_private_subnet_cidr'))
                ]))
        if network_creator is None or network_creator.get_network() is None:
            raise Exception("Failed to create private network")
        self.creators.append(network_creator)
Exemple #4
0
    def test_create_subnet_no_gateway(self):
        """
        Tests the creation of an OpenStack network with a subnet that has a
        valid value assigned to the gateway IP.
        """
        # Create Network
        subnet_config = SubnetConfig(
            name=self.guid + '-subnet', cidr=self.ip_prfx + '0/24',
            gateway_ip='none')
        net_config = NetworkConfig(
            name=self.guid + '-net', subnets=[subnet_config])
        self.net_creator = OpenStackNetwork(
            self.os_creds, net_config)
        out_net = self.net_creator.create()

        # Validate network was created
        self.assertTrue(neutron_utils_tests.validate_network(
            self.neutron, self.keystone,
            self.net_creator.network_settings.name, True,
            self.os_creds.project_name))

        # Validate subnets
        self.assertTrue(neutron_utils_tests.validate_subnet(
            self.neutron, out_net,
            self.net_creator.network_settings.subnet_settings[0].name,
            self.net_creator.network_settings.subnet_settings[0].cidr, True))

        self.assertIsNone(out_net.subnets[0].gateway_ip)
Exemple #5
0
    def test_create_subnet_valid_gateway_ip(self):
        """
        Tests the creation of an OpenStack network with a subnet that has a
        valid value assigned to the gateway IP.
        """
        # Create Network
        subnet_config = SubnetConfig(
            name=self.guid + '-subnet', cidr=self.ip_prfx + '0/24',
            gateway_ip=self.ip_prfx + '2')
        net_config = NetworkConfig(
            name=self.guid + '-net', subnets=[subnet_config])
        self.net_creator = OpenStackNetwork(
            self.os_creds, net_config)
        out_net = self.net_creator.create()

        self.assertIsNotNone(out_net)

        get_net = neutron_utils.get_network_by_id(self.neutron, out_net.id)
        self.assertIsNotNone(get_net)

        # Validate subnets
        self.assertTrue(neutron_utils_tests.validate_subnet(
            self.neutron, out_net,
            self.net_creator.network_settings.subnet_settings[0].name,
            self.net_creator.network_settings.subnet_settings[0].cidr, True))

        self.assertEqual(self.ip_prfx + '2', out_net.subnets[0].gateway_ip)
Exemple #6
0
def create_subnet_config(neutron, network):
    """
    Returns a list of SubnetConfig objects for a given network
    :param neutron: the OpenStack neutron client
    :param network: the SNAPS-OO Network domain object
    :return: a list
    """
    out = list()

    subnets = neutron_utils.get_subnets_by_network(neutron, network)
    for subnet in subnets:
        kwargs = dict()
        kwargs['cidr'] = subnet.cidr
        kwargs['ip_version'] = subnet.ip_version
        kwargs['name'] = subnet.name
        kwargs['start'] = subnet.start
        kwargs['end'] = subnet.end
        kwargs['gateway_ip'] = subnet.gateway_ip
        kwargs['enable_dhcp'] = subnet.enable_dhcp
        kwargs['dns_nameservers'] = subnet.dns_nameservers
        kwargs['host_routes'] = subnet.host_routes
        kwargs['ipv6_ra_mode'] = subnet.ipv6_ra_mode
        kwargs['ipv6_address_mode'] = subnet.ipv6_address_mode
        out.append(SubnetConfig(**kwargs))
    return out
Exemple #7
0
    def test_create_network_one_ipv6_subnet(self):
        """
        Tests the creation of an OpenStack network without a router.
        """
        # Create Network
        subnet_settings = SubnetConfig(
            name=self.guid + '-subnet', cidr='1:1:0:0:0:0:0:0/64',
            ip_version=6)
        network_settings = NetworkConfig(
            name=self.guid + '-net', subnet_settings=[subnet_settings])

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

        # Validate network was created
        self.assertTrue(neutron_utils_tests.validate_network(
            self.neutron, self.keystone,
            self.net_creator.network_settings.name, True,
            self.os_creds.project_name))

        network = self.net_creator.get_network()
        self.assertEqual(1, len(network.subnets))
        subnet = network.subnets[0]

        self.assertEqual(network.id, subnet.network_id)
        self.assertEqual(subnet_settings.name, subnet.name)
        self.assertEqual('1:1::/64', subnet.cidr)
        self.assertEqual(6, subnet.ip_version)
        self.assertEqual(0, len(subnet.dns_nameservers))
Exemple #8
0
    def test_derive_net_settings_two_subnets(self):
        """
        Validates the utility function settings_utils#create_network_config
        returns an acceptable NetworkConfig object
        """
        subnet_settings = list()
        subnet_settings.append(SubnetConfig(name='sub1', cidr='10.0.0.0/24'))
        subnet_settings.append(SubnetConfig(name='sub2', cidr='10.0.1.0/24'))
        net_settings = NetworkConfig(name=self.network_name,
                                     subnet_settings=subnet_settings)
        self.net_creator = OpenStackNetwork(self.os_creds, net_settings)
        network = self.net_creator.create()

        derived_settings = settings_utils.create_network_config(
            self.neutron, network)

        self.assertIsNotNone(derived_settings)
        self.assertEqual(net_settings.name, derived_settings.name)
        self.assertEqual(net_settings.admin_state_up,
                         derived_settings.admin_state_up)
        self.assertEqual(net_settings.external, derived_settings.external)
        self.assertEqual(len(net_settings.subnet_settings),
                         len(derived_settings.subnet_settings))

        # Validate the first subnet
        orig_sub1 = net_settings.subnet_settings[0]
        found = False
        for derived_sub in derived_settings.subnet_settings:
            if orig_sub1.name == derived_sub.name:
                self.assertEqual(orig_sub1.cidr, derived_sub.cidr)
                found = True

        self.assertTrue(found)

        # Validate the second subnet
        orig_sub2 = net_settings.subnet_settings[1]
        found = False
        for derived_sub in derived_settings.subnet_settings:
            if orig_sub2.name == derived_sub.name:
                self.assertEqual(orig_sub2.cidr, derived_sub.cidr)
                self.assertEqual(orig_sub2.ip_version, derived_sub.ip_version)
                found = True

        self.assertTrue(found)
Exemple #9
0
    def test_create_network_ipv4_ipv6_subnet(self):
        """
        Tests the creation of an OpenStack network without a router.
        """
        # Create Network
        subnet4_settings = SubnetConfig(
            name=self.guid + '-subnet4', cidr='10.0.1.0/24', ip_version=4)
        subnet6_settings = SubnetConfig(
            name=self.guid + '-subnet6', cidr='1:1:0:0:0:0:0:0/64',
            ip_version=6)

        network_settings = NetworkConfig(
            name=self.guid + '-net',
            subnet_settings=[subnet4_settings, subnet6_settings])

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

        # Validate network was created
        network = self.net_creator.get_network()
        self.assertEqual(2, len(network.subnets))

        subnet4 = None
        subnet6 = None
        for subnet in network.subnets:
            if subnet.name == subnet4_settings.name:
                subnet4 = subnet
            if subnet.name == subnet6_settings.name:
                subnet6 = subnet

        # Validate IPv4 subnet
        self.assertEqual(network.id, subnet4.network_id)
        self.assertEqual(subnet4_settings.name, subnet4.name)
        self.assertEqual(subnet4_settings.cidr, subnet4.cidr)
        self.assertEqual(4, subnet4.ip_version)
        self.assertEqual(0, len(subnet4.dns_nameservers))

        # Validate IPv6 subnet
        self.assertEqual(network.id, subnet6.network_id)
        self.assertEqual(subnet6_settings.name, subnet6.name)
        self.assertEqual('1:1::/64', subnet6.cidr)
        self.assertEqual(6, subnet6.ip_version)
        self.assertEqual(0, len(subnet6.dns_nameservers))
Exemple #10
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())
Exemple #11
0
    def test_create_subnet_invalid_gateway_ip(self):
        """
        Tests the creation of an OpenStack network with a subnet that has an
        invalid value assigned to the gateway IP.
        """
        # Create Network
        subnet_config = SubnetConfig(
            name=self.guid + '-subnet', cidr=self.ip_prfx + '0/24',
            gateway_ip='foo')
        net_config = NetworkConfig(
            name=self.guid + '-net', subnets=[subnet_config])
        self.net_creator = OpenStackNetwork(
            self.os_creds, net_config)

        with self.assertRaises(BadRequest):
            self.net_creator.create()
Exemple #12
0
    def __init__(self,
                 project_name,
                 net_name,
                 mtu=None,
                 subnet_name=None,
                 subnet_cidr=None,
                 router_name=None,
                 external_gateway=None,
                 netconf_override=None):
        """
        :param netconf_override: dict() containing the reconfigured
                                 network_type, physical_network and
                                 segmentation_id
        """
        if subnet_name and subnet_cidr:
            network_conf = NetworkConfig(name=net_name,
                                         mtu=mtu,
                                         subnet_settings=[
                                             SubnetConfig(cidr=subnet_cidr,
                                                          name=subnet_name)
                                         ])
        else:
            network_conf = NetworkConfig(name=net_name)
        if netconf_override:
            network_conf.network_type = netconf_override.get('network_type')
            network_conf.physical_network = netconf_override.get(
                'physical_network')
            network_conf.segmentation_id = netconf_override.get(
                'segmentation_id')
        self.network_settings = network_conf

        if router_name:
            if subnet_name:
                self.router_settings = RouterConfig(
                    name=router_name,
                    external_gateway=external_gateway,
                    internal_subnets=[{
                        'subnet': {
                            'project_name': project_name,
                            'network_name': net_name,
                            'subnet_name': subnet_name
                        }
                    }])
            else:
                self.router_settings = RouterConfig(
                    name=router_name, external_gateway=external_gateway)
Exemple #13
0
    def create(self,
               use_custom_images=False,
               use_custom_flavors=False,
               create_project=False):
        if create_project:
            logger.debug("Creating project (tenant) for Tempest suite")
            project_name = CONST.__getattribute__(
                'tempest_identity_tenant_name') + self.guid
            project_creator = deploy_utils.create_project(
                self.os_creds,
                ProjectConfig(name=project_name,
                              description=CONST.__getattribute__(
                                  'tempest_identity_tenant_description')))
            if (project_creator is None
                    or project_creator.get_project() is None):
                raise Exception("Failed to create tenant")
            project_id = project_creator.get_project().id
            self.creators.append(project_creator)

            logger.debug("Creating user for Tempest suite")
            user_creator = deploy_utils.create_user(
                self.os_creds,
                UserConfig(
                    name=CONST.__getattribute__('tempest_identity_user_name') +
                    self.guid,
                    password=CONST.__getattribute__(
                        'tempest_identity_user_password'),
                    project_name=project_name))
            if user_creator is None or user_creator.get_user() is None:
                raise Exception("Failed to create user")
            user_id = user_creator.get_user().id
            self.creators.append(user_creator)
        else:
            project_name = None
            project_id = None
            user_id = None

        logger.debug("Creating private network for Tempest suite")
        network_creator = deploy_utils.create_network(
            self.os_creds,
            NetworkConfig(
                name=CONST.__getattribute__('tempest_private_net_name') +
                self.guid,
                project_name=project_name,
                subnet_settings=[
                    SubnetConfig(name=CONST.__getattribute__(
                        'tempest_private_subnet_name') + self.guid,
                                 cidr=CONST.__getattribute__(
                                     'tempest_private_subnet_cidr'))
                ]))
        if network_creator is None or network_creator.get_network() is None:
            raise Exception("Failed to create private network")
        self.creators.append(network_creator)

        image_id = None
        image_id_alt = None
        flavor_id = None
        flavor_id_alt = None

        logger.debug("Creating image for Tempest suite")
        image_base_name = CONST.__getattribute__(
            'openstack_image_name') + self.guid
        os_image_settings = openstack_tests.cirros_image_settings(
            image_base_name,
            public=True,
            image_metadata=self.cirros_image_config)
        logger.debug("Creating image for Tempest suite")
        image_creator = deploy_utils.create_image(self.os_creds,
                                                  os_image_settings)
        if image_creator is None:
            raise Exception('Failed to create image')
        self.creators.append(image_creator)
        image_id = image_creator.get_image().id

        if use_custom_images:
            logger.debug("Creating 2nd image for Tempest suite")
            image_base_name_alt = CONST.__getattribute__(
                'openstack_image_name_alt') + self.guid
            os_image_settings_alt = openstack_tests.cirros_image_settings(
                image_base_name_alt,
                public=True,
                image_metadata=self.cirros_image_config)
            logger.debug("Creating 2nd image for Tempest suite")
            image_creator_alt = deploy_utils.create_image(
                self.os_creds, os_image_settings_alt)
            if image_creator_alt is None:
                raise Exception('Failed to create image')
            self.creators.append(image_creator_alt)
            image_id_alt = image_creator_alt.get_image().id

        if (CONST.__getattribute__('tempest_use_custom_flavors') == 'True'
                or use_custom_flavors):
            logger.info("Creating flavor for Tempest suite")
            scenario = CONST.__getattribute__('DEPLOY_SCENARIO')
            flavor_metadata = None
            if 'ovs' in scenario or 'fdio' in scenario:
                flavor_metadata = create_flavor.MEM_PAGE_SIZE_LARGE
            flavor_creator = OpenStackFlavor(
                self.os_creds,
                FlavorConfig(
                    name=CONST.__getattribute__('openstack_flavor_name') +
                    self.guid,
                    ram=CONST.__getattribute__('openstack_flavor_ram'),
                    disk=CONST.__getattribute__('openstack_flavor_disk'),
                    vcpus=CONST.__getattribute__('openstack_flavor_vcpus'),
                    metadata=flavor_metadata))
            flavor = flavor_creator.create()
            if flavor is None:
                raise Exception('Failed to create flavor')
            self.creators.append(flavor_creator)
            flavor_id = flavor.id

        if use_custom_flavors:
            logger.info("Creating 2nd flavor for Tempest suite")
            scenario = CONST.__getattribute__('DEPLOY_SCENARIO')
            flavor_metadata_alt = None
            if 'ovs' in scenario or 'fdio' in scenario:
                flavor_metadata_alt = create_flavor.MEM_PAGE_SIZE_LARGE
                CONST.__setattr__('openstack_flavor_ram', 1024)
            flavor_creator_alt = OpenStackFlavor(
                self.os_creds,
                FlavorConfig(
                    name=CONST.__getattribute__('openstack_flavor_name_alt') +
                    self.guid,
                    ram=CONST.__getattribute__('openstack_flavor_ram'),
                    disk=CONST.__getattribute__('openstack_flavor_disk'),
                    vcpus=CONST.__getattribute__('openstack_flavor_vcpus'),
                    metadata=flavor_metadata_alt))
            flavor_alt = flavor_creator_alt.create()
            if flavor_alt is None:
                raise Exception('Failed to create flavor')
            self.creators.append(flavor_creator_alt)
            flavor_id_alt = flavor_alt.id

        print("RESOURCES CREATE: image_id: %s, image_id_alt: %s, "
              "flavor_id: %s, flavor_id_alt: %s" % (
                  image_id,
                  image_id_alt,
                  flavor_id,
                  flavor_id_alt,
              ))

        result = {
            'image_id': image_id,
            'image_id_alt': image_id_alt,
            'flavor_id': flavor_id,
            'flavor_id_alt': flavor_id_alt
        }

        if create_project:
            result['project_id'] = project_id
            result['tenant_id'] = project_id  # for compatibility
            result['user_id'] = user_id

        return result
Exemple #14
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
Exemple #15
0
    def deploy_orchestrator(self):  # pylint: disable=too-many-locals
        """
        Create network, subnet, router

        Bootstrap juju
        """
        self.__logger.info("Deployed Orchestrator")
        private_net_name = getattr(
            CONST, 'vnf_{}_private_net_name'.format(self.case_name))
        private_subnet_name = getattr(
            CONST, 'vnf_{}_private_subnet_name'.format(self.case_name))
        private_subnet_cidr = getattr(
            CONST, 'vnf_{}_private_subnet_cidr'.format(self.case_name))
        abot_router = getattr(
            CONST, 'vnf_{}_external_router'.format(self.case_name))

        self.__logger.info("Creating full network ...")
        subnet_settings = SubnetConfig(
            name=private_subnet_name, cidr=private_subnet_cidr)
        network_settings = NetworkConfig(
            name=private_net_name, subnet_settings=[subnet_settings])
        network_creator = OpenStackNetwork(self.snaps_creds, network_settings)
        net_id = network_creator.create().id
        self.created_object.append(network_creator)

        ext_net_name = snaps_utils.get_ext_net_name(self.snaps_creds)
        self.__logger.info("Creating network Router ....")
        router_creator = OpenStackRouter(
            self.snaps_creds, RouterConfig(
                name=abot_router,
                external_gateway=ext_net_name,
                internal_subnets=[subnet_settings.name]))
        router_creator.create()
        self.created_object.append(router_creator)
        self.__logger.info("Creating Flavor ....")
        flavor_settings = FlavorConfig(
            name=self.orchestrator['requirements']['flavor']['name'],
            ram=self.orchestrator['requirements']['flavor']['ram_min'],
            disk=10, vcpus=1)
        flavor_creator = OpenStackFlavor(self.snaps_creds, flavor_settings)
        flavor_creator.create()
        self.created_object.append(flavor_creator)
        self.__logger.info("Upload some OS images if it doesn't exist")
        images = get_config("tenant_images", self.config_file)
        self.__logger.info("Images needed for vEPC: %s", images)
        for image_name, image_file in images.iteritems():
            self.__logger.info("image: %s, file: %s", image_name, image_file)
            if image_file and image_name:
                image_creator = OpenStackImage(self.snaps_creds, ImageConfig(
                    name=image_name, image_user='******', img_format='qcow2',
                    image_file=image_file))
                image_id = image_creator.create().id
                os.system(
                    'juju metadata generate-image -d ~ -i {} -s {} -r '
                    '{} -u {}'.format(
                        image_id, image_name,
                        os.environ.get(
                            "OS_REGION_NAME", self.default_region_name),
                        self.public_auth_url))
                self.created_object.append(image_creator)
        self.__logger.info("Credential information  : %s", net_id)
        juju_bootstrap_command = (
            'juju bootstrap abot-epc abot-controller --config network={} '
            '--metadata-source ~  --config ssl-hostname-verification=false '
            '--constraints mem=2G --bootstrap-series xenial '
            '--config use-floating-ip=true --debug '
            '--config use-default-secgroup=true'.format(net_id))
        os.system(juju_bootstrap_command)
        return True
Exemple #16
0
    def _prepare_env(self):
        """Create resources needed by test scenarios."""
        LOGGER.debug('Validating the test name...')
        if self.test_name not in self.TESTS:
            raise Exception("Test name '%s' is invalid" % self.test_name)

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

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

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

        rally_network_type = None
        rally_physical_network = None
        rally_segmentation_id = None

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

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

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

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

        LOGGER.debug("Creating flavor '%s'...", self.flavor_alt_name)
        flavor_alt_creator = OpenStackFlavor(
            self.os_creds, FlavorConfig(
                name=self.flavor_alt_name, ram=self.FLAVOR_RAM_ALT, disk=1,
                vcpus=1, metadata=self.FLAVOR_EXTRA_SPECS))
        if flavor_alt_creator is None or flavor_alt_creator.create() is None:
            raise Exception("Failed to create flavor")
        self.creators.append(flavor_alt_creator)
Exemple #17
0
    def deploy_orchestrator(self):  # pylint: disable=too-many-locals
        """
        Create network, subnet, router

        Bootstrap juju
        """
        self.__logger.info("Deployed Orchestrator")
        private_net_name = getattr(
            config.CONF, 'vnf_{}_private_net_name'.format(self.case_name))
        private_subnet_name = '{}-{}'.format(
            getattr(config.CONF,
                    'vnf_{}_private_subnet_name'.format(self.case_name)),
            self.uuid)
        private_subnet_cidr = getattr(
            config.CONF, 'vnf_{}_private_subnet_cidr'.format(self.case_name))
        abot_router = '{}-{}'.format(
            getattr(config.CONF,
                    'vnf_{}_external_router'.format(self.case_name)),
            self.uuid)
        self.__logger.info("Creating full network ...")
        subnet_settings = SubnetConfig(name=private_subnet_name,
                                       cidr=private_subnet_cidr,
                                       dns_nameservers=[env.get('NAMESERVER')])
        network_settings = NetworkConfig(name=private_net_name,
                                         subnet_settings=[subnet_settings])
        network_creator = OpenStackNetwork(self.snaps_creds, network_settings)
        net_id = network_creator.create().id
        self.created_object.append(network_creator)

        ext_net_name = snaps_utils.get_ext_net_name(self.snaps_creds)
        self.__logger.info("Creating network Router ....")
        router_creator = OpenStackRouter(
            self.snaps_creds,
            RouterConfig(name=abot_router,
                         external_gateway=ext_net_name,
                         internal_subnets=[subnet_settings.name]))
        router_creator.create()
        self.created_object.append(router_creator)
        self.__logger.info("Creating Flavor ....")
        flavor_settings = FlavorConfig(
            name=self.orchestrator['requirements']['flavor']['name'],
            ram=self.orchestrator['requirements']['flavor']['ram_min'],
            disk=10,
            vcpus=1)
        flavor_creator = OpenStackFlavor(self.snaps_creds, flavor_settings)
        flavor_creator.create()
        self.created_object.append(flavor_creator)
        self.__logger.info("Upload some OS images if it doesn't exist")
        images = get_config("tenant_images", self.config_file)
        self.__logger.info("Images needed for vEPC: %s", images)
        for image_name, image_file in images.iteritems():
            self.__logger.info("image: %s, file: %s", image_name, image_file)
            if image_file and image_name:
                image_creator = OpenStackImage(
                    self.snaps_creds,
                    ImageConfig(name=image_name,
                                image_user='******',
                                img_format='qcow2',
                                image_file=image_file))
                image_id = image_creator.create().id
                cmd = [
                    'timeout', '-t', JujuEpc.juju_timeout, 'juju', 'metadata',
                    'generate-image', '-d', '/root', '-i', image_id, '-s',
                    image_name, '-r', self.snaps_creds.region_name, '-u',
                    self.public_auth_url
                ]
                output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
                self.__logger.info("%s\n%s", " ".join(cmd), output)
                self.created_object.append(image_creator)
        self.__logger.info("Network ID  : %s", net_id)
        cmd = [
            'timeout', '-t', JujuEpc.juju_timeout, 'juju', 'bootstrap',
            'abot-epc', 'abot-controller', '--metadata-source', '/root',
            '--constraints', 'mem=2G', '--bootstrap-series', 'xenial',
            '--config', 'network={}'.format(net_id), '--config',
            'ssl-hostname-verification=false', '--config',
            'use-floating-ip=true', '--config', 'use-default-secgroup=true',
            '--debug'
        ]
        output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
        self.__logger.info("%s\n%s", " ".join(cmd), output)
        return True
Exemple #18
0
image_settings = ImageConfig(
    name='cirros-test',
    image_user='******',
    img_format='qcow2',
    url='http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img')

image = OpenStackImage(os_creds, image_settings)
image.create()
# See in Horizon

# Network
from snaps.config.network import NetworkConfig, SubnetConfig
from snaps.openstack.create_network import OpenStackNetwork

subnet_settings = SubnetConfig(name='test-subnet', cidr='10.0.0.1/24')
network_settings = NetworkConfig(name='test-net',
                                 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
Exemple #19
0
    def run(self, **kwargs):  # pylint: disable=too-many-locals
        """
        Begins the test execution which should originate from the subclass
        """
        self.logger.info('Begin virtual environment setup')

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

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

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

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

        vping_network_type = None
        vping_physical_network = None
        vping_segmentation_id = None

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

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

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

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