Exemple #1
0
    def test_create_project_sec_grp_one_user(self):
        """
        Tests the creation of an OpenStack object to a project with a new users
        and to create a security group
        """
        self.project_creator = OpenStackProject(self.os_creds,
                                                self.project_settings)
        created_project = self.project_creator.create()
        self.assertIsNotNone(created_project)

        user_creator = OpenStackUser(
            self.os_creds,
            UserConfig(name=self.guid + '-user',
                       password=self.guid,
                       roles={'admin': self.project_settings.name},
                       domain_name=self.os_creds.user_domain_name))
        self.project_creator.assoc_user(user_creator.create())
        self.user_creators.append(user_creator)

        sec_grp_os_creds = user_creator.get_os_creds(
            self.project_creator.get_project().name)
        sec_grp_creator = OpenStackSecurityGroup(
            sec_grp_os_creds,
            SecurityGroupConfig(name=self.guid + '-name',
                                description='hello group'))
        sec_grp = sec_grp_creator.create()
        self.assertIsNotNone(sec_grp)
        self.sec_grp_creators.append(sec_grp_creator)

        self.assertEqual(self.project_creator.get_project().id,
                         sec_grp.project_id)
Exemple #2
0
    def create_security_group(self, sec_grp_name):
        logger.info("Creating the security groups...")
        rule_ping = SecurityGroupRuleConfig(sec_grp_name=sec_grp_name,
                                            direction=Direction.ingress,
                                            protocol=Protocol.icmp)

        rule_ssh = SecurityGroupRuleConfig(sec_grp_name=sec_grp_name,
                                           direction=Direction.ingress,
                                           protocol=Protocol.tcp,
                                           port_range_min=22,
                                           port_range_max=22)

        rule_http = SecurityGroupRuleConfig(sec_grp_name=sec_grp_name,
                                            direction=Direction.ingress,
                                            protocol=Protocol.tcp,
                                            port_range_min=80,
                                            port_range_max=80)

        rules = [rule_ping, rule_ssh, rule_http]

        secgroup_settings = SecurityGroupConfig(name=sec_grp_name,
                                                rule_settings=rules)

        sec_group_creator = OpenStackSecurityGroup(self.os_creds,
                                                   secgroup_settings)
        sec_group = sec_group_creator.create()

        self.creators.append(sec_group_creator)

        return sec_group
Exemple #3
0
def create_security_group(os_creds, sec_grp_settings):
    """
    Creates an OpenStack Security Group
    :param os_creds: The OpenStack credentials
    :param sec_grp_settings: The security group settings
    :return: A reference to the project instance object
    """
    sg_creator = OpenStackSecurityGroup(os_creds, sec_grp_settings)
    sg_creator.create()
    return sg_creator
    def prepare_security_groups(self):
        """Create Open Baton security group if it doesn't exist yet"""
        self.logger.info(
            "Creating security group for Open Baton if not yet existing...")
        sg_rules = list()
        sg_rules.append(
            SecurityGroupRuleConfig(
                sec_grp_name="orchestra-sec-group-allowall",
                direction=Direction.ingress,
                protocol=Protocol.tcp,
                port_range_min=1,
                port_range_max=65535))
        sg_rules.append(
            SecurityGroupRuleConfig(
                sec_grp_name="orchestra-sec-group-allowall",
                direction=Direction.egress,
                protocol=Protocol.tcp,
                port_range_min=1,
                port_range_max=65535))
        sg_rules.append(
            SecurityGroupRuleConfig(
                sec_grp_name="orchestra-sec-group-allowall",
                direction=Direction.ingress,
                protocol=Protocol.udp,
                port_range_min=1,
                port_range_max=65535))
        sg_rules.append(
            SecurityGroupRuleConfig(
                sec_grp_name="orchestra-sec-group-allowall",
                direction=Direction.egress,
                protocol=Protocol.udp,
                port_range_min=1,
                port_range_max=65535))
        sg_rules.append(
            SecurityGroupRuleConfig(
                sec_grp_name="orchestra-sec-group-allowall",
                direction=Direction.ingress,
                protocol=Protocol.icmp))
        sg_rules.append(
            SecurityGroupRuleConfig(
                sec_grp_name="orchestra-sec-group-allowall",
                direction=Direction.egress,
                protocol=Protocol.icmp))
        security_group = OpenStackSecurityGroup(
            self.snaps_creds,
            SecurityGroupConfig(
                name="orchestra-sec-group-allowall",
                rule_settings=sg_rules))

        security_group_info = security_group.create()
        self.created_resources.append(security_group)
        self.mano['details']['sec_group'] = security_group_info.name
        self.logger.info(
            "Security group orchestra-sec-group-allowall prepared")
Exemple #5
0
 def _add_custom_rule(self, sec_grp_name):
     """ To add custom rule for SCTP Traffic """
     sec_grp_rules = list()
     sec_grp_rules.append(
         SecurityGroupRuleConfig(sec_grp_name=sec_grp_name,
                                 direction=Direction.ingress,
                                 protocol=Protocol.sctp))
     security_group = OpenStackSecurityGroup(
         self.snaps_creds,
         SecurityGroupConfig(name=sec_grp_name,
                             rule_settings=sec_grp_rules))
     security_group.create()
     self.created_object.append(security_group)
Exemple #6
0
    def setUp(self):
        """
        Initializes objects used for router testing
        """
        super(self.__class__, self).__start__()

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

        self.sec_grp_creator = OpenStackSecurityGroup(
            self.os_creds, SecurityGroupConfig(name=self.guid + '-sec_grp'))
        self.sec_grp_creator.create()

        self.neutron = neutron_utils.neutron_client(self.os_creds,
                                                    self.os_session)
Exemple #7
0
    def get_security_group_creators(self):
        """
        Returns a list of security group creator objects as configured by the
        heat template
        :return: list() of OpenStackNetwork objects
        """

        out = list()
        stack_security_groups = heat_utils.get_stack_security_groups(
            self.__heat_cli, self.__neutron, self.__stack)

        for stack_security_group in stack_security_groups:
            settings = settings_utils.create_security_group_config(
                self.__neutron, stack_security_group)
            creator = OpenStackSecurityGroup(self._os_creds, settings)
            out.append(creator)
            creator.initialize()

        return out
Exemple #8
0
    def setUp(self):
        """
        Instantiates the CreateSecurityGroup object that is responsible for
        downloading and creating an OS image file within OpenStack
        """
        super(self.__class__, self).__start__()

        guid = self.__class__.__name__ + '-' + str(uuid.uuid4())
        self.sec_grp_name = guid + 'name'
        self.neutron = neutron_utils.neutron_client(self.os_creds,
                                                    self.os_session)

        # Initialize for cleanup
        self.admin_sec_grp_config = SecurityGroupConfig(
            name=self.sec_grp_name, description='hello group')
        self.sec_grp_creator_admin = OpenStackSecurityGroup(
            self.admin_os_creds, self.admin_sec_grp_config)
        self.sec_grp_creator_admin.create()
        self.sec_grp_creator_proj = None
Exemple #9
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 #10
0
    def test_create_group_admin_user_to_new_project(self):
        """
        Tests the creation of an OpenStack Security Group without custom rules.
        """
        # Create Security Group
        sec_grp_settings = SecurityGroupConfig(
            name=self.sec_grp_name,
            description='hello group',
            project_name=self.os_creds.project_name)
        self.sec_grp_creator = OpenStackSecurityGroup(self.admin_os_creds,
                                                      sec_grp_settings)
        self.sec_grp_creator.create()

        sec_grp = neutron_utils.get_security_group(
            self.neutron, self.keystone, sec_grp_settings=sec_grp_settings)
        self.assertIsNotNone(sec_grp)

        validation_utils.objects_equivalent(
            self.sec_grp_creator.get_security_group(), sec_grp)
        rules = neutron_utils.get_rules_by_security_group(
            self.neutron, self.sec_grp_creator.get_security_group())
        self.assertEqual(len(self.sec_grp_creator.get_rules()), len(rules))
        validation_utils.objects_equivalent(self.sec_grp_creator.get_rules(),
                                            rules)

        self.assertTrue(
            validate_sec_grp(self.neutron, self.keystone,
                             self.sec_grp_creator.sec_grp_settings,
                             self.sec_grp_creator.get_security_group(), rules))

        self.assertEqual(self.sec_grp_creator.get_security_group().id,
                         sec_grp.id)

        proj_creator = OpenStackSecurityGroup(
            self.os_creds, SecurityGroupConfig(name=self.sec_grp_name))
        proj_creator.create()

        self.assertEqual(self.sec_grp_creator.get_security_group().id,
                         proj_creator.get_security_group().id)
Exemple #11
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
Exemple #12
0
class AnsibleProvisioningTests(OSIntegrationTestCase):
    """
    Test for the CreateInstance class with two NIC/Ports, eth0 with floating IP
    and eth1 w/o
    """
    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

    def tearDown(self):
        """
        Cleans the created objects
        """
        if self.inst_creator:
            try:
                self.inst_creator.clean()
            except:
                pass

        if self.sec_grp_creator:
            try:
                self.sec_grp_creator.clean()
            except:
                pass

        if self.keypair_creator:
            try:
                self.keypair_creator.clean()
            except:
                pass

        if self.flavor_creator:
            try:
                self.flavor_creator.clean()
            except:
                pass

        if os.path.isfile(self.keypair_pub_filepath):
            try:
                os.remove(self.keypair_pub_filepath)
            except:
                pass

        if os.path.isfile(self.keypair_priv_filepath):
            try:
                os.remove(self.keypair_priv_filepath)
            except:
                pass

        if self.router_creator:
            try:
                self.router_creator.clean()
            except:
                pass

        if self.network_creator:
            try:
                self.network_creator.clean()
            except:
                pass

        if self.image_creator and not self.image_creator.image_settings.exists:
            try:
                self.image_creator.clean()
            except:
                pass

        if os.path.isfile(self.test_file_local_path):
            os.remove(self.test_file_local_path)

        super(self.__class__, self).__clean__()

    def test_apply_simple_playbook(self):
        """
        Tests application of an Ansible playbook that simply copies over a file
        1. Have a ~/.ansible.cfg (or alternate means) to
           set host_key_checking = False
        2. Set the following environment variable in your executing shell:
           ANSIBLE_HOST_KEY_CHECKING=False
        Should this not be performed, the creation of the host ssh key will
        cause your ansible calls to fail.
        """
        self.inst_creator.create(block=True)

        priv_ip = self.inst_creator.get_port_ip(self.port_1_name)
        self.assertTrue(check_dhcp_lease(self.inst_creator, priv_ip))

        # Apply Security Group
        self.inst_creator.add_security_group(
            self.sec_grp_creator.get_security_group())

        # Block until VM's ssh port has been opened
        self.assertTrue(self.inst_creator.vm_ssh_active(block=True))

        # Block until cloud-init has completed
        self.assertTrue(self.inst_creator.cloud_init_complete(block=True))

        ssh_client = self.inst_creator.ssh_client()
        self.assertIsNotNone(ssh_client)

        try:
            out = ssh_client.exec_command('pwd')[1].channel.in_buffer.read(
                1024)
            self.assertIsNotNone(out)
            self.assertGreater(len(out), 1)
        finally:
            ssh_client.close()

        # Need to use the first floating IP as subsequent ones are currently
        # broken with Apex CO
        ip = self.inst_creator.get_floating_ip().ip
        user = self.inst_creator.get_image_user()
        priv_key = self.inst_creator.keypair_settings.private_filepath

        relative_pb_path = pkg_resources.resource_filename(
            'snaps.provisioning.tests.playbooks', 'simple_playbook.yml')
        self.inst_creator.apply_ansible_playbook(relative_pb_path)

        ssh = ansible_utils.ssh_client(
            ip,
            user,
            private_key_filepath=priv_key,
            proxy_settings=self.os_creds.proxy_settings)
        self.assertIsNotNone(ssh)
        scp = None
        try:
            scp = SCPClient(ssh.get_transport())
            scp.get('~/hello.txt', self.test_file_local_path)
        finally:
            if scp:
                scp.close()
            ssh.close()

        self.assertTrue(os.path.isfile(self.test_file_local_path))

        test_file = None

        try:
            with open(self.test_file_local_path) as test_file:
                file_contents = test_file.readline()
                self.assertEqual('Hello World!', file_contents)
        finally:
            if test_file:
                test_file.close()

    def test_apply_template_playbook(self):
        """
        Tests application of an Ansible playbook that applies a template to a
        file:
        1. Have a ~/.ansible.cfg (or alternate means) to set
           host_key_checking = False
        2. Set the following environment variable in your executing shell:
           ANSIBLE_HOST_KEY_CHECKING=False
        Should this not be performed, the creation of the host ssh key will
        cause your ansible calls to fail.
        """
        self.inst_creator.create(block=True)

        priv_ip = self.inst_creator.get_port_ip(self.port_1_name)
        self.assertTrue(check_dhcp_lease(self.inst_creator, priv_ip))

        # Apply Security Group
        self.inst_creator.add_security_group(
            self.sec_grp_creator.get_security_group())

        # Block until VM's ssh port has been opened
        self.assertTrue(self.inst_creator.vm_ssh_active(block=True))

        # Block until cloud-init has completed
        self.assertTrue(self.inst_creator.cloud_init_complete(block=True))

        # Apply Security Group
        self.inst_creator.add_security_group(
            self.sec_grp_creator.get_security_group())

        # Need to use the first floating IP as subsequent ones are currently
        # broken with Apex CO
        ip = self.inst_creator.get_floating_ip().ip
        user = self.inst_creator.get_image_user()
        priv_key = self.inst_creator.keypair_settings.private_filepath

        relative_pb_path = pkg_resources.resource_filename(
            'snaps.provisioning.tests.playbooks', 'template_playbook.yml')
        self.inst_creator.apply_ansible_playbook(relative_pb_path,
                                                 variables={'name': 'Foo'})

        ssh = ansible_utils.ssh_client(
            ip,
            user,
            private_key_filepath=priv_key,
            proxy_settings=self.os_creds.proxy_settings)
        self.assertIsNotNone(ssh)
        scp = None

        try:
            scp = SCPClient(ssh.get_transport())
            scp.get('/tmp/hello.txt', self.test_file_local_path)
        finally:
            if scp:
                scp.close()
            ssh.close()

        self.assertTrue(os.path.isfile(self.test_file_local_path))

        test_file = None
        try:
            with open(self.test_file_local_path) as test_file:
                file_contents = test_file.readline()
                self.assertEqual('Hello Foo!', file_contents)
        finally:
            if test_file:
                test_file.close()
Exemple #13
0
class CreateRouterSecurityGroupTests(OSIntegrationTestCase):
    """
    Class for testing routers with ports containing security groups
    """
    def setUp(self):
        """
        Initializes objects used for router testing
        """
        super(self.__class__, self).__start__()

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

        self.sec_grp_creator = OpenStackSecurityGroup(
            self.os_creds, SecurityGroupConfig(name=self.guid + '-sec_grp'))
        self.sec_grp_creator.create()

        self.neutron = neutron_utils.neutron_client(self.os_creds,
                                                    self.os_session)

    def tearDown(self):
        """
        Cleans the remote OpenStack objects used for router testing
        """
        if self.router_creator:
            self.router_creator.clean()

        if self.network_creator:
            self.network_creator.clean()

        if self.sec_grp_creator:
            self.sec_grp_creator.clean()

        super(self.__class__, self).__clean__()

    def test_create_router_secure_port(self):
        """
        Test creation of a router with a port that has a security group.
        """
        network_settings = NetworkConfig(
            name=self.guid + '-pub-net1',
            subnet_settings=[
                create_network.SubnetConfig(cidr=cidr1,
                                            name=self.guid + '-pub-subnet1')
            ])
        self.network_creator = OpenStackNetwork(self.os_creds,
                                                network_settings)
        self.network_creator.create()

        port_settings = [
            create_network.PortConfig(
                name=self.guid + '-port1',
                ip_addrs=[{
                    'subnet_name': network_settings.subnet_settings[0].name,
                    'ip': static_gateway_ip1
                }],
                network_name=network_settings.name,
                security_groups=[self.sec_grp_creator.sec_grp_settings.name])
        ]

        router_settings = RouterConfig(name=self.guid + '-pub-router',
                                       external_gateway=self.ext_net_name,
                                       port_settings=port_settings)
        self.router_creator = create_router.OpenStackRouter(
            self.os_creds, router_settings)
        self.router_creator.create()
Exemple #14
0
class SettingsUtilsVmInstTests(OSComponentTestCase):
    """
    Tests the ability to reverse engineer VmInstanceConfig objects from
    existing VMs/servers deployed to OpenStack
    """
    def setUp(self):
        """
        Instantiates the CreateImage object that is responsible for downloading
        and creating an OS image file within OpenStack
        """
        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.glance = glance_utils.glance_client(self.os_creds,
                                                 self.os_session)
        self.neutron = neutron_utils.neutron_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.cirros_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',
                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
            self.flavor_creator = create_flavor.OpenStackFlavor(
                self.os_creds,
                FlavorConfig(name=guid + '-flavor-name',
                             ram=256,
                             disk=1,
                             vcpus=1))
            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

    def tearDown(self):
        """
        Cleans the created objects
        """
        if self.inst_creator:
            try:
                self.inst_creator.clean()
            except:
                pass

        if self.sec_grp_creator:
            try:
                self.sec_grp_creator.clean()
            except:
                pass

        if self.keypair_creator:
            try:
                self.keypair_creator.clean()
            except:
                pass

        if self.flavor_creator:
            try:
                self.flavor_creator.clean()
            except:
                pass

        if os.path.isfile(self.keypair_pub_filepath):
            try:
                os.remove(self.keypair_pub_filepath)
            except:
                pass

        if os.path.isfile(self.keypair_priv_filepath):
            try:
                os.remove(self.keypair_priv_filepath)
            except:
                pass

        if self.router_creator:
            try:
                self.router_creator.clean()
            except:
                pass

        if self.network_creator:
            try:
                self.network_creator.clean()
            except:
                pass

        if self.image_creator and not self.image_creator.image_settings.exists:
            try:
                self.image_creator.clean()
            except:
                pass

        if os.path.isfile(self.test_file_local_path):
            os.remove(self.test_file_local_path)

        super(self.__class__, self).__clean__()

    def test_derive_vm_inst_config(self):
        """
        Validates the utility function settings_utils#create_vm_inst_config
        returns an acceptable VmInstanceConfig object
        """
        self.inst_creator.create(block=True)

        server = nova_utils.get_server(
            self.nova,
            self.neutron,
            self.keystone,
            vm_inst_settings=self.inst_creator.instance_settings)
        derived_vm_settings = settings_utils.create_vm_inst_config(
            self.nova, self.keystone, self.neutron, server,
            self.os_creds.project_name)
        self.assertIsNotNone(derived_vm_settings)
        self.assertIsNotNone(derived_vm_settings.port_settings)
        self.assertIsNotNone(derived_vm_settings.floating_ip_settings)

    def test_derive_image_settings(self):
        """
        Validates the utility function settings_utils#create_image_settings
        returns an acceptable ImageConfig object
        """
        self.inst_creator.create(block=True)

        server = nova_utils.get_server(
            self.nova,
            self.neutron,
            self.keystone,
            vm_inst_settings=self.inst_creator.instance_settings)
        derived_image_settings = settings_utils.determine_image_config(
            self.glance, server, [self.image_creator.image_settings])
        self.assertIsNotNone(derived_image_settings)
        self.assertEqual(self.image_creator.image_settings.name,
                         derived_image_settings.name)
    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_vrouter.pem")
        keypair_settings = KeypairSettings(name='cloudify_vrouter_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 = SubnetSettings(name='cloudify_vrouter_subnet',
                                         cidr='10.67.79.0/24')
        network_settings = NetworkSettings(name='cloudify_vrouter_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,
            RouterSettings(name='cloudify_vrouter_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(
            SecurityGroupRuleSettings(sec_grp_name="sg-cloudify-manager",
                                      direction=Direction.ingress,
                                      protocol=Protocol.tcp,
                                      port_range_min=1,
                                      port_range_max=65535))
        sg_rules.append(
            SecurityGroupRuleSettings(sec_grp_name="sg-cloudify-manager",
                                      direction=Direction.ingress,
                                      protocol=Protocol.udp,
                                      port_range_min=1,
                                      port_range_max=65535))

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

        security_group_creator.create()
        self.created_object.append(security_group_creator)

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

        flavor_settings = FlavorSettings(
            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 = ImageSettings(
            name=self.orchestrator['requirements']['os_image'],
            image_user='******',
            exists=True)

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

        manager_settings = VmInstanceSettings(
            name='cloudify_manager',
            flavor=flavor_settings.name,
            port_settings=[port_settings],
            security_group_names=[
                security_group_creator.sec_grp_settings.name
            ],
            floating_ip_settings=[
                FloatingIpSettings(
                    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 = os_utils.get_endpoint('identity')

        self.__logger.info("Set creds for cloudify manager")
        cfy_creds = dict(keystone_username=self.tenant_name,
                         keystone_password=self.tenant_name,
                         keystone_tenant_name=self.tenant_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.cfy_manager_ip = manager_creator.get_floating_ip().ip

        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_vrouter.pem /etc/cloudify/"
            run_blocking_ssh_command(ssh, cmd)
            cmd = "sudo chmod 444 /etc/cloudify/cloudify_vrouter.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))

        return True
Exemple #16
0
    def test_sec_grp_same_name_diff_proj(self):
        """
        Tests the creation of an OpenStack Security Group with the same name
        within a different project/tenant.
        """
        # Create Security Group
        sec_grp_config = SecurityGroupConfig(name=self.sec_grp_name,
                                             description='hello group')
        self.sec_grp_creator_proj = OpenStackSecurityGroup(
            self.os_creds, sec_grp_config)
        self.sec_grp_creator_proj.create()

        self.assertNotEqual(self.sec_grp_creator_admin.get_security_group().id,
                            self.sec_grp_creator_proj.get_security_group().id)

        admin_sec_grp_creator = OpenStackSecurityGroup(
            self.admin_os_creds, self.admin_sec_grp_config)
        admin_sec_grp_creator.create()
        self.assertEqual(self.sec_grp_creator_admin.get_security_group().id,
                         admin_sec_grp_creator.get_security_group().id)

        proj_sec_grp_creator = OpenStackSecurityGroup(self.os_creds,
                                                      sec_grp_config)
        proj_sec_grp_creator.create()
        self.assertEqual(self.sec_grp_creator_proj.get_security_group().id,
                         proj_sec_grp_creator.get_security_group().id)
Exemple #17
0
class CreateMultipleSecurityGroupTests(OSIntegrationTestCase):
    """
    Test for the CreateSecurityGroup class and how it interacts with security
    groups within other projects with the same name
    """
    def setUp(self):
        """
        Instantiates the CreateSecurityGroup object that is responsible for
        downloading and creating an OS image file within OpenStack
        """
        super(self.__class__, self).__start__()

        guid = self.__class__.__name__ + '-' + str(uuid.uuid4())
        self.sec_grp_name = guid + 'name'
        self.neutron = neutron_utils.neutron_client(self.os_creds,
                                                    self.os_session)

        # Initialize for cleanup
        self.admin_sec_grp_config = SecurityGroupConfig(
            name=self.sec_grp_name, description='hello group')
        self.sec_grp_creator_admin = OpenStackSecurityGroup(
            self.admin_os_creds, self.admin_sec_grp_config)
        self.sec_grp_creator_admin.create()
        self.sec_grp_creator_proj = None

    def tearDown(self):
        """
        Cleans the image and downloaded image file
        """
        if self.sec_grp_creator_admin:
            self.sec_grp_creator_admin.clean()
        if self.sec_grp_creator_proj:
            self.sec_grp_creator_proj.clean()

        super(self.__class__, self).__clean__()

    def test_sec_grp_same_name_diff_proj(self):
        """
        Tests the creation of an OpenStack Security Group with the same name
        within a different project/tenant.
        """
        # Create Security Group
        sec_grp_config = SecurityGroupConfig(name=self.sec_grp_name,
                                             description='hello group')
        self.sec_grp_creator_proj = OpenStackSecurityGroup(
            self.os_creds, sec_grp_config)
        self.sec_grp_creator_proj.create()

        self.assertNotEqual(self.sec_grp_creator_admin.get_security_group().id,
                            self.sec_grp_creator_proj.get_security_group().id)

        admin_sec_grp_creator = OpenStackSecurityGroup(
            self.admin_os_creds, self.admin_sec_grp_config)
        admin_sec_grp_creator.create()
        self.assertEqual(self.sec_grp_creator_admin.get_security_group().id,
                         admin_sec_grp_creator.get_security_group().id)

        proj_sec_grp_creator = OpenStackSecurityGroup(self.os_creds,
                                                      sec_grp_config)
        proj_sec_grp_creator.create()
        self.assertEqual(self.sec_grp_creator_proj.get_security_group().id,
                         proj_sec_grp_creator.get_security_group().id)
Exemple #18
0
class CreateSecurityGroupTests(OSIntegrationTestCase):
    """
    Test for the CreateSecurityGroup class defined in create_security_group.py
    """
    def setUp(self):
        """
        Instantiates the CreateSecurityGroup object that is responsible for
        downloading and creating an OS image file within OpenStack
        """
        super(self.__class__, self).__start__()

        guid = self.__class__.__name__ + '-' + str(uuid.uuid4())
        self.sec_grp_name = guid + 'name'
        self.neutron = neutron_utils.neutron_client(self.os_creds,
                                                    self.os_session)

        # Initialize for cleanup
        self.sec_grp_creator = None

    def tearDown(self):
        """
        Cleans the image and downloaded image file
        """
        if self.sec_grp_creator:
            self.sec_grp_creator.clean()

        super(self.__class__, self).__clean__()

    def test_create_group_without_rules(self):
        """
        Tests the creation of an OpenStack Security Group without custom rules.
        """
        # Create Security Group
        sec_grp_settings = SecurityGroupConfig(name=self.sec_grp_name,
                                               description='hello group')
        self.sec_grp_creator = create_security_group.OpenStackSecurityGroup(
            self.os_creds, sec_grp_settings)
        self.sec_grp_creator.create()

        sec_grp = neutron_utils.get_security_group(
            self.neutron, self.keystone, sec_grp_settings=sec_grp_settings)
        self.assertIsNotNone(sec_grp)

        validation_utils.objects_equivalent(
            self.sec_grp_creator.get_security_group(), sec_grp)
        rules = neutron_utils.get_rules_by_security_group(
            self.neutron, self.sec_grp_creator.get_security_group())
        self.assertEqual(len(self.sec_grp_creator.get_rules()), len(rules))
        validation_utils.objects_equivalent(self.sec_grp_creator.get_rules(),
                                            rules)

        self.assertTrue(
            validate_sec_grp(self.neutron, self.keystone,
                             self.sec_grp_creator.sec_grp_settings,
                             self.sec_grp_creator.get_security_group()))

    def test_create_group_admin_user_to_new_project(self):
        """
        Tests the creation of an OpenStack Security Group without custom rules.
        """
        # Create Security Group
        sec_grp_settings = SecurityGroupConfig(
            name=self.sec_grp_name,
            description='hello group',
            project_name=self.os_creds.project_name)
        self.sec_grp_creator = OpenStackSecurityGroup(self.admin_os_creds,
                                                      sec_grp_settings)
        self.sec_grp_creator.create()

        sec_grp = neutron_utils.get_security_group(
            self.neutron, self.keystone, sec_grp_settings=sec_grp_settings)
        self.assertIsNotNone(sec_grp)

        validation_utils.objects_equivalent(
            self.sec_grp_creator.get_security_group(), sec_grp)
        rules = neutron_utils.get_rules_by_security_group(
            self.neutron, self.sec_grp_creator.get_security_group())
        self.assertEqual(len(self.sec_grp_creator.get_rules()), len(rules))
        validation_utils.objects_equivalent(self.sec_grp_creator.get_rules(),
                                            rules)

        self.assertTrue(
            validate_sec_grp(self.neutron, self.keystone,
                             self.sec_grp_creator.sec_grp_settings,
                             self.sec_grp_creator.get_security_group(), rules))

        self.assertEqual(self.sec_grp_creator.get_security_group().id,
                         sec_grp.id)

        proj_creator = OpenStackSecurityGroup(
            self.os_creds, SecurityGroupConfig(name=self.sec_grp_name))
        proj_creator.create()

        self.assertEqual(self.sec_grp_creator.get_security_group().id,
                         proj_creator.get_security_group().id)

    def test_create_group_new_user_to_admin_project(self):
        """
        Tests the creation of an OpenStack Security Group without custom rules.
        """
        # Create Security Group
        sec_grp_settings = SecurityGroupConfig(
            name=self.sec_grp_name,
            description='hello group',
            project_name=self.os_creds.project_name)
        self.sec_grp_creator = create_security_group.OpenStackSecurityGroup(
            self.admin_os_creds, sec_grp_settings)
        self.sec_grp_creator.create()

        sec_grp = neutron_utils.get_security_group(
            self.neutron, self.keystone, sec_grp_settings=sec_grp_settings)
        self.assertIsNotNone(sec_grp)

        validation_utils.objects_equivalent(
            self.sec_grp_creator.get_security_group(), sec_grp)
        rules = neutron_utils.get_rules_by_security_group(
            self.neutron, self.sec_grp_creator.get_security_group())
        self.assertEqual(len(self.sec_grp_creator.get_rules()), len(rules))
        validation_utils.objects_equivalent(self.sec_grp_creator.get_rules(),
                                            rules)

        self.assertTrue(
            validate_sec_grp(self.neutron, self.keystone,
                             self.sec_grp_creator.sec_grp_settings,
                             self.sec_grp_creator.get_security_group(), rules))

    def test_create_delete_group(self):
        """
        Tests the creation of an OpenStack Security Group without custom rules.
        """
        # Create Security Group
        sec_grp_settings = SecurityGroupConfig(name=self.sec_grp_name,
                                               description='hello group')
        self.sec_grp_creator = create_security_group.OpenStackSecurityGroup(
            self.os_creds, sec_grp_settings)
        created_sec_grp = self.sec_grp_creator.create()
        self.assertIsNotNone(created_sec_grp)

        self.assertTrue(
            validate_sec_grp(self.neutron, self.keystone,
                             self.sec_grp_creator.sec_grp_settings,
                             self.sec_grp_creator.get_security_group()))

        neutron_utils.delete_security_group(self.neutron, created_sec_grp)
        self.assertIsNone(
            neutron_utils.get_security_group(
                self.neutron,
                self.keystone,
                sec_grp_settings=self.sec_grp_creator.sec_grp_settings))

        self.sec_grp_creator.clean()

    def test_create_group_with_one_simple_rule(self):
        """
        Tests the creation of an OpenStack Security Group with one simple
        custom rule.
        """
        # Create Security Group
        sec_grp_rule_settings = list()
        sec_grp_rule_settings.append(
            SecurityGroupRuleConfig(sec_grp_name=self.sec_grp_name,
                                    direction=Direction.ingress,
                                    description='test_rule_1'))
        sec_grp_settings = SecurityGroupConfig(
            name=self.sec_grp_name,
            description='hello group',
            rule_settings=sec_grp_rule_settings)
        self.sec_grp_creator = create_security_group.OpenStackSecurityGroup(
            self.os_creds, sec_grp_settings)
        self.sec_grp_creator.create()

        sec_grp = neutron_utils.get_security_group(
            self.neutron, self.keystone, sec_grp_settings=sec_grp_settings)
        validation_utils.objects_equivalent(
            self.sec_grp_creator.get_security_group(), sec_grp)
        rules = neutron_utils.get_rules_by_security_group(
            self.neutron, self.sec_grp_creator.get_security_group())
        self.assertEqual(len(self.sec_grp_creator.get_rules()), len(rules))
        validation_utils.objects_equivalent(self.sec_grp_creator.get_rules(),
                                            rules)

        self.assertTrue(
            validate_sec_grp(self.neutron, self.keystone,
                             self.sec_grp_creator.sec_grp_settings,
                             self.sec_grp_creator.get_security_group(), rules))

    def test_create_group_with_one_complex_rule(self):
        """
        Tests the creation of an OpenStack Security Group with one simple
        custom rule.
        """
        # Create Security Group
        sec_grp_rule_settings = list()
        sec_grp_rule_settings.append(
            SecurityGroupRuleConfig(sec_grp_name=self.sec_grp_name,
                                    direction=Direction.egress,
                                    protocol=Protocol.udp,
                                    ethertype=Ethertype.IPv4,
                                    port_range_min=10,
                                    port_range_max=20,
                                    description='test_rule_1'))
        sec_grp_settings = SecurityGroupConfig(
            name=self.sec_grp_name,
            description='hello group',
            rule_settings=sec_grp_rule_settings)
        self.sec_grp_creator = create_security_group.OpenStackSecurityGroup(
            self.os_creds, sec_grp_settings)
        self.sec_grp_creator.create()

        sec_grp = neutron_utils.get_security_group(
            self.neutron, self.keystone, sec_grp_settings=sec_grp_settings)
        validation_utils.objects_equivalent(
            self.sec_grp_creator.get_security_group(), sec_grp)
        rules = neutron_utils.get_rules_by_security_group(
            self.neutron, self.sec_grp_creator.get_security_group())
        self.assertEqual(len(self.sec_grp_creator.get_rules()), len(rules))
        validation_utils.objects_equivalent(self.sec_grp_creator.get_rules(),
                                            rules)

        self.assertTrue(
            validate_sec_grp(self.neutron, self.keystone,
                             self.sec_grp_creator.sec_grp_settings,
                             self.sec_grp_creator.get_security_group(), rules))

    def test_create_group_with_several_rules(self):
        """
        Tests the creation of an OpenStack Security Group with one simple
        custom rule.
        """
        # Create Security Group
        sec_grp_rule_settings = list()
        sec_grp_rule_settings.append(
            SecurityGroupRuleConfig(sec_grp_name=self.sec_grp_name,
                                    direction=Direction.ingress,
                                    description='test_rule_1'))
        sec_grp_rule_settings.append(
            SecurityGroupRuleConfig(sec_grp_name=self.sec_grp_name,
                                    direction=Direction.egress,
                                    protocol=Protocol.udp,
                                    ethertype=Ethertype.IPv6,
                                    description='test_rule_2'))
        sec_grp_rule_settings.append(
            SecurityGroupRuleConfig(sec_grp_name=self.sec_grp_name,
                                    direction=Direction.egress,
                                    protocol=Protocol.udp,
                                    ethertype=Ethertype.IPv4,
                                    port_range_min=10,
                                    port_range_max=20,
                                    description='test_rule_3'))
        sec_grp_settings = SecurityGroupConfig(
            name=self.sec_grp_name,
            description='hello group',
            rule_settings=sec_grp_rule_settings)
        self.sec_grp_creator = create_security_group.OpenStackSecurityGroup(
            self.os_creds, sec_grp_settings)
        self.sec_grp_creator.create()

        sec_grp = neutron_utils.get_security_group(
            self.neutron, self.keystone, sec_grp_settings=sec_grp_settings)
        validation_utils.objects_equivalent(
            self.sec_grp_creator.get_security_group(), sec_grp)
        rules = neutron_utils.get_rules_by_security_group(
            self.neutron, self.sec_grp_creator.get_security_group())
        self.assertEqual(len(self.sec_grp_creator.get_rules()), len(rules))
        validation_utils.objects_equivalent(self.sec_grp_creator.get_rules(),
                                            rules)

        self.assertTrue(
            validate_sec_grp(self.neutron, self.keystone,
                             self.sec_grp_creator.sec_grp_settings,
                             self.sec_grp_creator.get_security_group(), rules))

    def test_add_rule(self):
        """
        Tests the creation of an OpenStack Security Group with one simple
        custom rule then adds one after creation.
        """
        # Create Security Group
        sec_grp_rule_settings = list()
        sec_grp_rule_settings.append(
            SecurityGroupRuleConfig(sec_grp_name=self.sec_grp_name,
                                    direction=Direction.ingress,
                                    description='test_rule_1'))
        sec_grp_settings = SecurityGroupConfig(
            name=self.sec_grp_name,
            description='hello group',
            rule_settings=sec_grp_rule_settings)
        self.sec_grp_creator = create_security_group.OpenStackSecurityGroup(
            self.os_creds, sec_grp_settings)
        self.sec_grp_creator.create()

        sec_grp = neutron_utils.get_security_group(
            self.neutron, self.keystone, sec_grp_settings=sec_grp_settings)
        validation_utils.objects_equivalent(
            self.sec_grp_creator.get_security_group(), sec_grp)

        rules = neutron_utils.get_rules_by_security_group(
            self.neutron, self.sec_grp_creator.get_security_group())

        self.assertTrue(
            validate_sec_grp(self.neutron, self.keystone,
                             self.sec_grp_creator.sec_grp_settings,
                             self.sec_grp_creator.get_security_group(), rules))

        rules = neutron_utils.get_rules_by_security_group(
            self.neutron, self.sec_grp_creator.get_security_group())
        self.assertEqual(len(self.sec_grp_creator.get_rules()), len(rules))
        validation_utils.objects_equivalent(self.sec_grp_creator.get_rules(),
                                            rules)

        self.sec_grp_creator.add_rule(
            SecurityGroupRuleConfig(
                sec_grp_name=self.sec_grp_creator.sec_grp_settings.name,
                direction=Direction.egress,
                protocol=Protocol.icmp,
                description='test_rule_2'))
        rules2 = neutron_utils.get_rules_by_security_group(
            self.neutron, self.sec_grp_creator.get_security_group())
        self.assertEqual(len(rules) + 1, len(rules2))

    def test_remove_rule_by_id(self):
        """
        Tests the creation of an OpenStack Security Group with two simple
        custom rules then removes one by the rule ID.
        """
        # Create Security Group
        sec_grp_rule_settings = list()
        sec_grp_rule_settings.append(
            SecurityGroupRuleConfig(sec_grp_name=self.sec_grp_name,
                                    direction=Direction.ingress,
                                    description='test_rule_1'))
        sec_grp_rule_settings.append(
            SecurityGroupRuleConfig(sec_grp_name=self.sec_grp_name,
                                    direction=Direction.egress,
                                    protocol=Protocol.udp,
                                    ethertype=Ethertype.IPv6,
                                    description='test_rule_2'))
        sec_grp_rule_settings.append(
            SecurityGroupRuleConfig(sec_grp_name=self.sec_grp_name,
                                    direction=Direction.egress,
                                    protocol=Protocol.udp,
                                    ethertype=Ethertype.IPv4,
                                    port_range_min=10,
                                    port_range_max=20,
                                    description='test_rule_3'))
        sec_grp_settings = SecurityGroupConfig(
            name=self.sec_grp_name,
            description='hello group',
            rule_settings=sec_grp_rule_settings)
        self.sec_grp_creator = create_security_group.OpenStackSecurityGroup(
            self.os_creds, sec_grp_settings)
        self.sec_grp_creator.create()

        sec_grp = neutron_utils.get_security_group(
            self.neutron, self.keystone, sec_grp_settings=sec_grp_settings)
        validation_utils.objects_equivalent(
            self.sec_grp_creator.get_security_group(), sec_grp)
        rules = neutron_utils.get_rules_by_security_group(
            self.neutron, self.sec_grp_creator.get_security_group())
        self.assertEqual(len(self.sec_grp_creator.get_rules()), len(rules))
        validation_utils.objects_equivalent(self.sec_grp_creator.get_rules(),
                                            rules)

        self.assertTrue(
            validate_sec_grp(self.neutron, self.keystone,
                             self.sec_grp_creator.sec_grp_settings,
                             self.sec_grp_creator.get_security_group(), rules))

        self.sec_grp_creator.remove_rule(rule_id=rules[0].id)
        rules_after_del = neutron_utils.get_rules_by_security_group(
            self.neutron, self.sec_grp_creator.get_security_group())
        self.assertEqual(len(rules) - 1, len(rules_after_del))

    def test_remove_rule_by_setting(self):
        """
        Tests the creation of an OpenStack Security Group with two simple
        custom rules then removes one by the rule setting object
        """
        # Create Security Group
        sec_grp_rule_settings = list()
        sec_grp_rule_settings.append(
            SecurityGroupRuleConfig(sec_grp_name=self.sec_grp_name,
                                    direction=Direction.ingress,
                                    description='test_rule_1'))
        sec_grp_rule_settings.append(
            SecurityGroupRuleConfig(sec_grp_name=self.sec_grp_name,
                                    direction=Direction.egress,
                                    protocol=Protocol.udp,
                                    ethertype=Ethertype.IPv6,
                                    description='test_rule_2'))
        sec_grp_rule_settings.append(
            SecurityGroupRuleConfig(sec_grp_name=self.sec_grp_name,
                                    direction=Direction.egress,
                                    protocol=Protocol.udp,
                                    ethertype=Ethertype.IPv4,
                                    port_range_min=10,
                                    port_range_max=20,
                                    description='test_rule_3'))
        sec_grp_settings = SecurityGroupConfig(
            name=self.sec_grp_name,
            description='hello group',
            rule_settings=sec_grp_rule_settings)
        self.sec_grp_creator = create_security_group.OpenStackSecurityGroup(
            self.os_creds, sec_grp_settings)
        self.sec_grp_creator.create()

        sec_grp = neutron_utils.get_security_group(
            self.neutron, self.keystone, sec_grp_settings=sec_grp_settings)
        validation_utils.objects_equivalent(
            self.sec_grp_creator.get_security_group(), sec_grp)

        rules = neutron_utils.get_rules_by_security_group(
            self.neutron, self.sec_grp_creator.get_security_group())
        self.assertEqual(len(self.sec_grp_creator.get_rules()), len(rules))
        validation_utils.objects_equivalent(self.sec_grp_creator.get_rules(),
                                            rules)

        self.assertTrue(
            validate_sec_grp(self.neutron, self.keystone,
                             self.sec_grp_creator.sec_grp_settings,
                             self.sec_grp_creator.get_security_group(), rules))

        self.sec_grp_creator.remove_rule(rule_setting=sec_grp_rule_settings[0])
        rules_after_del = neutron_utils.get_rules_by_security_group(
            self.neutron, self.sec_grp_creator.get_security_group())
        self.assertEqual(len(rules) - 1, len(rules_after_del))
    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