def nsxt_public_network_availability(self):
        """Check connectivity from VMs to public network.

        Scenario:
            1. Set up for system tests.
            2. Get access to OpenStack.
            3. Launch two instances in default network. Instances should belong
               to different az (nova and vcenter).
            4. Send ping from each instance to 8.8.8.8.

        Duration: 30 min
        """
        self.show_step(1)  # Set up for system tests
        self.env.revert_snapshot('nsxt_setup_system')

        self.show_step(2)  # Get access to OpenStack
        cluster_id = self.fuel_web.get_last_created_cluster()

        os_ip = self.fuel_web.get_public_vip(cluster_id)
        os_conn = os_actions.OpenStackActions(
            os_ip, SERVTEST_USERNAME,
            SERVTEST_PASSWORD,
            SERVTEST_TENANT)

        # Launch two instances in default network. Instances should belong to
        # different az (nova and vcenter)
        self.show_step(3)
        sg = os_conn.create_sec_group_for_ssh().name
        vm1 = os_help.create_instance(os_conn, sg_names=[sg], az='vcenter')
        vm2 = os_help.create_instance(os_conn, sg_names=[sg])

        # Send ping from each instance to 8.8.8.8
        self.show_step(4)
        vm1_fip, vm2_fip = \
            os_help.create_and_assign_floating_ips(os_conn, [vm1, vm2])

        os_help.check_connection_vms({vm1_fip: ['8.8.8.8'],
                                      vm2_fip: ['8.8.8.8']})
    def verify_manila_functionality(self, share_prot='nfs', clean_up=True,
                                    backend='generic'):
        """This method do basic functionality check :

               * creates share-type, share network, share, access_rule ;
               * start instance using configuration from server-conf.yaml;
               * mount share  verify R/W to mounted share;
        """

        # create default share type
        # cli:manila type-create default_share_type True
        logger.info('#'*10 + "Create manila default share type" + '#'*10)
        share_type = self.manila_conn.create_share_type(
            type_name='default_share_type')
        asserts.assert_equal(share_type.name, 'default_share_type',
                             message="Failed to create default share type")
        self.manila_conn.set_share_type_extrascpecs(
            share_type.name,
            {'share_backend_name': backend}
        )

        logger.info('#'*10 + "share type id : " + str(share_type.id))
        # get internal id of admin_internal_net network and subnet id
        # neutron net-list | grep  'admin_internal_net'
        network = self.os_conn.get_network('admin_internal_net')
        logger.debug('admin_internal_net id is :{}'.format(network))

        # create share network (share network = internal_admin_network)
        logger.info('#'*10 + "Create manila share network" + '#' * 10)
        s_net = self.manila_conn.create_share_network(
            net_id=network.get('id'), subnet_id=network.get('subnets'))
        logger.info('#' * 10 + "share type id : " + str(s_net.name))
        asserts.assert_equal(s_net.name, 'test_share_network',
                             message="Failed to create manila share network")

        share_network_id = s_net.id
        logger.info('#'*10 + "Manila share network ID :{0}".format(s_net.id))

        # create share and wait until it will becomes available
        logger.info('#'*10 + "Create manila share" + '#' * 10)
        test_share = self.manila_conn.create_basic_share(
            protocol=share_prot,
            share_name='test_share', network=share_network_id)
        asserts.assert_equal(test_share.name, 'test_share',
                             message="Failed to create manila share")
        self.manila_conn.wait_for_share_status(
            share_name='test_share', status='available')
        logger.info('#'*10 + "Share created and become available")

        logger.info('#'*10 + "add access rule allow any ip for created share")
        self.manila_conn.add_acc_rule(share_id=test_share, rule='0.0.0.0/0')

        logger.info('#'*10 + "Create and configure instance to verify share")
        test_instance, sec_group = openstack.create_instance(self.os_conn)
        openstack.verify_instance_state(self.os_conn, 'test_share_server')

        logger.info('#'*10 + "Assign floating ip for server")
        fl_ip = openstack.create_and_assign_floating_ips(
            self.os_conn, test_instance)
        logger.info("IP: {0} user: {1} pass:{1}".format(fl_ip, 'manila'))

        logger.info('#'*10 + "Connect via ssh to server")
        ssh_client = openstack.get_ssh_connection(fl_ip)

        msg = 'New instance started floating ip is: {0}'.format(fl_ip)
        logger.info(msg)

        self.verify_share_mount(ssh_client, test_share, share_prot)

        if clean_up:
            logger.info('#'*10 + "Cleanup test objects" + '#'*10)
            logger.info('#' * 10 + "Delete test instance")
            openstack.delete_instance(self.os_conn, test_instance)
            logger.info('#' * 10 + "Delete test security group")
            openstack.delete_sec_group(self.os_conn, sec_group.id)

            logger.info('#' * 10 + "Delete test share")
            self.manila_conn.delete_all_shares()
            logger.info('#' * 10 + "Delete test share network")
            self.manila_conn.delete_all_share_networks()
            logger.info('#' * 10 + "Delete test share type ")
            self.manila_conn.delete_all_share_types()
    def nsxt_manage_secgroups(self):
        """Check ability to create and delete security group.

        Scenario:
            1. Set up for system tests.
            2. Get access to OpenStack.
            3. Create new security group with default rules.
            4. Add ingress rule for ICMP protocol.
            5. Launch two instances in default network. Instances should
               belong to different az (nova and vcenter).
            6. Attach created security group to instances.
            7. Check that instances can ping each other.
            8. Delete ingress rule for ICMP protocol.
            9. Check that instances can't ping each other.
            10. Delete instances.
            11. Delete security group.

        Duration: 30 min
        """
        self.show_step(1)  # Set up for system tests
        self.env.revert_snapshot('nsxt_setup_system')

        self.show_step(2)  # Get access to OpenStack
        cluster_id = self.fuel_web.get_last_created_cluster()
        os_conn = os_actions.OpenStackActions(
            self.fuel_web.get_public_vip(cluster_id),
            SERVTEST_USERNAME,
            SERVTEST_PASSWORD,
            SERVTEST_TENANT)

        # Create new security group with default rules
        self.show_step(3)
        sg1 = os_conn.nova.security_groups.create('SG_1', 'test-icmp')

        # Add ingress rule for ICMP protocol
        self.show_step(4)
        icmp = {
            'ip_protocol': 'icmp',
            'from_port': -1,
            'to_port': -1,
            'cidr': '0.0.0.0/0'
        }
        sg1_rule = os_conn.nova.security_group_rules.create(sg1.id, **icmp)

        # Launch two instances in default network. Instances should belong to
        # different az (nova and vcenter)
        self.show_step(5)
        ssh = {
            'ip_protocol': 'tcp',
            'from_port': 22,
            'to_port': 22,
            'cidr': '0.0.0.0/0'
        }
        ssh_sg = os_conn.nova.security_groups.create('ssh_sg', 'test-ssh')
        os_conn.nova.security_group_rules.create(ssh_sg.id, **ssh)

        vm1 = os_help.create_instance(os_conn, sg_names=[ssh_sg.name])
        vm2 = os_help.create_instance(os_conn, sg_names=[ssh_sg.name],
                                      az='vcenter')

        # Attach created security group to instances
        self.show_step(6)
        os_conn.nova.servers.add_security_group(vm1, sg1.name)
        os_conn.nova.servers.add_security_group(vm2, sg1.name)

        # Check that instances can ping each other
        self.show_step(7)
        vm1_fip, vm2_fip = \
            os_help.create_and_assign_floating_ips(os_conn, [vm1, vm2])

        net_name = self.default.PRIVATE_NET
        vm1_ip = os_conn.get_nova_instance_ip(vm1, net_name=net_name)
        vm2_ip = os_conn.get_nova_instance_ip(vm2, net_name=net_name)

        os_help.check_connection_vms({vm1_fip: [vm2_ip], vm2_fip: [vm1_ip]})

        # Delete ingress rule for ICMP protocol
        self.show_step(8)
        os_conn.nova.security_group_rules.delete(sg1_rule)

        # Check that instances can't ping each other
        self.show_step(9)
        os_help.check_connection_vms({vm1_fip: [vm2_ip], vm2_fip: [vm1_ip]},
                                     result_of_command=1)

        # Delete instances
        self.show_step(10)
        os_conn.delete_instance(vm1)
        os_conn.delete_instance(vm2)
        os_conn.verify_srv_deleted(vm1)
        os_conn.verify_srv_deleted(vm2)

        # Delete security group
        self.show_step(11)
        os_conn.nova.security_groups.delete(sg1)
        os_conn.nova.security_groups.delete(ssh_sg)
    def nsxt_connectivity_diff_networks(self):
        """Check connection between VMs from different nets through the router.

        Scenario:
            1. Set up for system tests.
            2. Get access to OpenStack.
            3. Add two private networks (net01 and net02).
            4. Add one subnet  to each network
                 net01_subnet01: 192.168.101.0/24,
                 net02_subnet01: 192.168.102.0/24.
               Disable gateway for both subnets.
            5. Launch 1 instance in each network. Instances should belong to
               different az (nova and vcenter).
            6. Create new router (Router_01), set gateway and add interface
               to external network.
            7. Enable gateway on subnets. Attach private networks to created
               router.
            8. Verify that VMs of different networks communicate between
               each other.
            9. Add one more router (Router_02), set gateway and add interface
               to external network.
            10. Detach net_02 from Router_01 and attach it to Router_02.
            11. Assign floating IPs for all created VMs.
            12. Check that default security group allows the ICMP.
            13. Verify that VMs of different networks communicate between
                each other by FIPs.
            14. Delete instances.
            15. Detach created networks from routers.
            16. Delete created networks.
            17. Delete created routers.

        Duration: 30 min
        """
        self.show_step(1)  # Set up for system tests
        self.env.revert_snapshot('nsxt_setup_system')

        self.show_step(2)  # Get access to OpenStack
        cluster_id = self.fuel_web.get_last_created_cluster()
        os_conn = os_actions.OpenStackActions(
            self.fuel_web.get_public_vip(cluster_id),
            SERVTEST_USERNAME,
            SERVTEST_PASSWORD,
            SERVTEST_TENANT)

        self.show_step(3)  # Add two private networks (net01 and net02)
        net1 = self._create_net(os_conn, 'net_01')
        net2 = self._create_net(os_conn, 'net_02')

        # Add one subnet to each network: net01_subnet01 (192.168.101.0/24) and
        # net02_subnet01 (192.168.102.0/24). Disable gateway for both subnets
        self.show_step(4)
        subnet1 = os_conn.create_subnet(
            subnet_name='net01_subnet01',
            network_id=net1['id'],
            cidr='192.168.101.0/24',
            allocation_pools=[
                {'start': '192.168.101.2','end': '192.168.101.254'}
            ],
            ip_version=4,
            gateway_ip=None)

        subnet2 = os_conn.create_subnet(
            subnet_name='net02_subnet01',
            network_id=net2['id'],
            cidr='192.168.102.0/24',
            allocation_pools=[
                {'start': '192.168.102.2', 'end': '192.168.102.254'}
            ],
            ip_version=4,
            gateway_ip=None)

        # Launch 1 instance in each network. Instances should belong to
        # different az (nova and vcenter)
        self.show_step(5)
        sg = os_conn.create_sec_group_for_ssh().name
        vm1 = os_help.create_instance(os_conn, net=net1, sg_names=[sg],
                                      az='vcenter')
        vm2 = os_help.create_instance(os_conn, net=net2, sg_names=[sg])

        # Create new router (Router_01), set gateway and add interface to
        # external network
        self.show_step(6)
        tenant = os_conn.get_tenant(SERVTEST_TENANT)
        router1 = os_conn.create_router('Router_01', tenant)

        # Enable gateway on subnets. Attach private networks to created router
        self.show_step(7)
        os_help.add_gateway_ip(os_conn, subnet1['id'], '192.168.101.1')
        os_conn.add_router_interface(router_id=router1['id'],
                                     subnet_id=subnet1['id'])

        os_help.add_gateway_ip(os_conn, subnet2['id'], '192.168.102.1')
        os_conn.add_router_interface(router_id=router1['id'],
                                     subnet_id=subnet2['id'])

        # Verify that VMs of different networks communicate between each other
        self.show_step(8)
        vm1_ip = os_conn.get_nova_instance_ip(vm1, net_name=net1['name'])
        vm2_ip = os_conn.get_nova_instance_ip(vm2, net_name=net2['name'])

        vm1_fip, vm2_fip = \
            os_help.create_and_assign_floating_ips(os_conn, [vm1, vm2])

        os_help.check_connection_vms({vm1_fip: [vm2_ip], vm2_fip: [vm1_ip]})

        # Add one more router (Router_02), set gateway and add interface
        # to external network
        self.show_step(9)
        router2 = os_conn.create_router('Router_02', tenant)

        # Detach net_02 from Router_01 and attach it to Router_02
        self.show_step(10)
        vm2.remove_floating_ip(vm2_fip)
        os_help.remove_router_interface(os_conn, router1['id'], subnet2['id'])
        os_conn.add_router_interface(router_id=router2['id'],
                                     subnet_id=subnet2['id'])

        self.show_step(11)  # Assign floating IPs for all created VMs
        vm2_fip = os_help.create_and_assign_floating_ips(os_conn, [vm2])[0]

        self.show_step(12)  # Check that default security group allow the ICMP

        # Verify that VMs of different networks communicate between each
        # other by FIPs
        self.show_step(13)
        os_help.check_connection_vms({vm1_fip: [vm2_fip], vm2_fip: [vm1_fip]})

        self.show_step(14)  # Delete instances
        vm1.remove_floating_ip(vm1_fip)
        vm2.remove_floating_ip(vm2_fip)
        os_conn.delete_instance(vm1)
        os_conn.delete_instance(vm2)

        self.show_step(15)  # Detach created networks from routers
        os_help.remove_router_interface(os_conn, router1['id'], subnet1['id'])
        os_help.remove_router_interface(os_conn, router2['id'], subnet2['id'])

        os_conn.verify_srv_deleted(vm2)
        os_conn.verify_srv_deleted(vm1)

        self.show_step(16)  # Delete created networks
        os_conn.neutron.delete_network(net1['id'])
        os_conn.neutron.delete_network(net2['id'])

        self.show_step(17)  # Delete created routers
        os_conn.neutron.delete_router(router1['id'])
        os_conn.neutron.delete_router(router2['id'])
    def dvs_destructive_setup_2(self):
        """Verify that vmclusters migrate after reset controller.

        Scenario:
            1. Upload plugins to the master node.
            2. Install plugin.
            3. Configure cluster with 2 vcenter clusters.
            4. Add 3 node with controller role.
            5. Add 2 node with compute role.
            6. Configure vcenter.
            7. Deploy the cluster.
            8. Run smoke OSTF tests
            9. Launch instances. 1 per az. Assign floating ips.
            10. Make snapshot.

        Duration: 1.8 hours
        Snapshot: dvs_destructive_setup_2
        """
        self.show_step(1)
        self.env.revert_snapshot("ready_with_5_slaves")

        plugin.install_dvs_plugin(self.ssh_manager.admin_ip)

        self.show_step(2)
        cluster_id = self.fuel_web.create_cluster(
            name=self.__class__.__name__,
            mode=DEPLOYMENT_MODE,
            settings={
                "net_provider": 'neutron',
                "net_segment_type": NEUTRON_SEGMENT_TYPE
            }
        )
        plugin.enable_plugin(cluster_id, self.fuel_web)

        self.show_step(3)
        self.show_step(4)
        self.fuel_web.update_nodes(cluster_id,
                                   {'slave-01': ['controller'],
                                    'slave-02': ['controller'],
                                    'slave-03': ['controller'],
                                    'slave-04': ['compute'],
                                    'slave-05': ['compute']})
        self.show_step(6)
        self.fuel_web.vcenter_configure(cluster_id, multiclusters=True)

        self.show_step(7)
        self.fuel_web.deploy_cluster_wait(cluster_id)

        self.show_step(8)
        self.fuel_web.run_ostf(cluster_id=cluster_id, test_sets=['smoke'])

        self.show_step(9)
        os_ip = self.fuel_web.get_public_vip(cluster_id)
        os_conn = os_actions.OpenStackActions(
            os_ip, SERVTEST_USERNAME,
            SERVTEST_PASSWORD,
            SERVTEST_TENANT)

        security_group = os_conn.create_sec_group_for_ssh()

        network = os_conn.nova.networks.find(label=self.inter_net_name)
        instances = openstack.create_instances(
            os_conn=os_conn,
            nics=[{'net-id': network.id}],
            vm_count=1,
            security_groups=[security_group.name])
        openstack.verify_instance_state(os_conn)
        openstack.create_and_assign_floating_ips(os_conn, instances)

        self.show_step(10)
        self.env.make_snapshot("dvs_destructive_setup_2", is_make=True)
    def dvs_regression(self):
        """Deploy cluster with plugin and vmware datastore backend.

        Scenario:
            1. Revert to dvs_bvt snapshot.
            2. Create non default network net_1.
            3. Launch instances with created network in nova and vcenter az.
            4. Create Security groups.
            5. Attached created security groups to instances.
            6. Check connection between instances from different az.

        Duration: 1.8 hours
        """
        self.show_step(1)
        self.env.revert_snapshot("dvs_bvt")

        cluster_id = self.fuel_web.get_last_created_cluster()

        os_ip = self.fuel_web.get_public_vip(cluster_id)
        os_conn = os_actions.OpenStackActions(os_ip, SERVTEST_USERNAME,
                                              SERVTEST_PASSWORD,
                                              SERVTEST_TENANT)

        tenant = os_conn.get_tenant(SERVTEST_TENANT)

        # Create non default network with subnet
        self.show_step(2)

        logger.info('Create network {}'.format(self.net_data[0].keys()[0]))
        net_1 = os_conn.create_network(network_name=self.net_data[0].keys()[0],
                                       tenant_id=tenant.id)['network']

        subnet = os_conn.create_subnet(
            subnet_name=net_1['name'],
            network_id=net_1['id'],
            cidr=self.net_data[0][self.net_data[0].keys()[0]],
            ip_version=4)

        # Check that network are created
        assert_true(os_conn.get_network(net_1['name'])['id'] == net_1['id'])

        # Add net_1 to default router
        router = os_conn.get_router(os_conn.get_network(self.ext_net_name))
        os_conn.add_router_interface(router_id=router["id"],
                                     subnet_id=subnet["id"])

        self.show_step(3)

        # Launch 2 vcenter VMs and 2 nova VMs in the tenant network net_01
        openstack.create_instances(os_conn=os_conn,
                                   vm_count=1,
                                   nics=[{
                                       'net-id': net_1['id']
                                   }])

        # Launch 2 vcenter VMs and 2 nova VMs in the default network
        net_1 = os_conn.nova.networks.find(label=self.inter_net_name)
        instances = openstack.create_instances(os_conn=os_conn,
                                               vm_count=1,
                                               nics=[{
                                                   'net-id': net_1.id
                                               }])
        openstack.verify_instance_state(os_conn)

        self.show_step(4)

        # Create security groups SG_1 to allow ICMP traffic.
        # Add Ingress rule for ICMP protocol to SG_1
        # Create security groups SG_2 to allow TCP traffic 22 port.
        # Add Ingress rule for TCP protocol to SG_2
        sec_name = ['SG1', 'SG2']
        sg1 = os_conn.nova.security_groups.create(sec_name[0], "descr")
        sg2 = os_conn.nova.security_groups.create(sec_name[1], "descr")
        rulesets = [
            {
                # ssh
                'ip_protocol': 'tcp',
                'from_port': 22,
                'to_port': 22,
                'cidr': '0.0.0.0/0',
            },
            {
                # ping
                'ip_protocol': 'icmp',
                'from_port': -1,
                'to_port': -1,
                'cidr': '0.0.0.0/0',
            }
        ]
        os_conn.nova.security_group_rules.create(sg1.id, **rulesets[0])
        os_conn.nova.security_group_rules.create(sg2.id, **rulesets[1])

        # Remove default security group and attach SG_1 and SG2 to VMs
        self.show_step(5)

        srv_list = os_conn.get_servers()
        for srv in srv_list:
            srv.remove_security_group(srv.security_groups[0]['name'])
            srv.add_security_group(sg1.id)
            srv.add_security_group(sg2.id)
        fip = openstack.create_and_assign_floating_ips(os_conn, instances)

        # Check ping between VMs
        self.show_step(6)

        ip_pair = dict.fromkeys(fip)
        for key in ip_pair:
            ip_pair[key] = [value for value in fip if key != value]
        openstack.check_connection_vms(ip_pair)
    def dvs_vcenter_bind_port(self):
        """Check abilities to bind port on DVS to VM, disable/enable this port.

        Scenario:
            1. Revert snapshot to dvs_vcenter_destructive_setup
            2. Create private networks net01 with sunet.
            3. Launch instances VM_1 and VM_2 in the net01
               with image TestVM and flavor m1.micro in nova az.
            4. Launch instances VM_3 and VM_4 in the net01
               with image TestVM-VMDK and flavor m1.micro in nova az.
            4. Bind sub_net port of instances.
            5. Check instances are not available.
            6. Enable sub_net port of all instances.
            7. Verify that instances should communicate between each other.
               Send icmp ping between instances.


        Duration: 1,5 hours

        """
        self.env.revert_snapshot("dvs_vcenter_systest_setup")

        cluster_id = self.fuel_web.get_last_created_cluster()

        # Create new network
        os_ip = self.fuel_web.get_public_vip(cluster_id)
        os_conn = os_actions.OpenStackActions(
            os_ip, SERVTEST_USERNAME,
            SERVTEST_PASSWORD,
            SERVTEST_TENANT)

        # create security group with rules for ssh and ping
        security_group = os_conn.create_sec_group_for_ssh()

        logger.info("Create non default network with subnet.")
        logger.info('Create network {}'.format(self.net_data[0].keys()[0]))
        network = os_conn.create_network(
            network_name=self.net_data[0].keys()[0])['network']

        subnet = os_conn.create_subnet(
            subnet_name=network['name'],
            network_id=network['id'],
            cidr=self.net_data[0][self.net_data[0].keys()[0]])

        logger.info("Check that network are created.")
        assert_true(
            os_conn.get_network(network['name'])['id'] == network['id']
        )

        logger.info("Add net_1 to default router")
        router = os_conn.get_router(os_conn.get_network(self.ext_net_name))
        os_conn.add_router_interface(
            router_id=router["id"],
            subnet_id=subnet["id"])

        #  Launch instance VM_1 and VM_2
        instances = openstack.create_instances(
            os_conn=os_conn, nics=[{'net-id': network['id']}], vm_count=1,
            security_groups=[security_group.name]
        )
        openstack.verify_instance_state(os_conn)

        ports = os_conn.neutron.list_ports()['ports']
        floating_ip = openstack.create_and_assign_floating_ips(
            os_conn, instances)
        instance_ports = []
        for instance in instances:
            instance_addr = os_conn.get_nova_instance_ip(
                instance, net_name=network['name'])
            for port in ports:
                port_addr = port['fixed_ips'][0]['ip_address']
                if instance_addr == port_addr:
                    instance_ports.append(port)
        for port in instance_ports:
            os_conn.neutron.update_port(
                port['id'], {'port': {'admin_state_up': False}}
            )

        controller = self.fuel_web.get_nailgun_primary_node(
            self.env.d_env.nodes().slaves[0]
        )
        with self.fuel_web.get_ssh_for_node(controller.name) as ssh_controller:
            # Verify that not connection to instances
            try:
                openstack.check_connection_vms(
                    os_conn, floating_ip, remote=ssh_controller,
                    command='pingv4')
            except Exception as e:
                logger.info(str(e))

            # Enable sub_net ports of instances
            for port in instance_ports:
                os_conn.neutron.update_port(
                    port['id'], {'port': {'admin_state_up': True}}
                )

                instance.reboot()
                wait(
                    lambda:
                    os_conn.get_instance_detail(instance).status == "ACTIVE",
                    timeout=300)

            time.sleep(60)  # need time after reboot to get ip by instance

            # Verify that instances should communicate between each other.
            # Send icmp ping between instances
            openstack.check_connection_vms(
                os_conn, floating_ip, remote=ssh_controller,
                command='pingv4')
    def dvs_vcenter_bind_port(self):
        """Check abilities to bind port on DVS to VM, disable/enable this port.

        Scenario:
            1. Revert snapshot to dvs_vcenter_systest_setup.
            2. Create private networks net01 with subnet.
            3. Launch instance VM_1 in the net01 with
               image TestVM and flavor m1.micro in nova az.
            4. Launch instance VM_2 in the net01 with
               image TestVM-VMDK and flavor m1.micro in vcenter az.
            5. Disable sub_net port of instances.
            6. Check instances are not available.
            7. Enable sub_net port of all instances.
            8. Verify that instances communicate between each other.
               Send icmp ping between instances.

        Duration: 1,5 hours

        """
        self.show_step(1)
        self.env.revert_snapshot("dvs_vcenter_systest_setup")

        cluster_id = self.fuel_web.get_last_created_cluster()

        os_ip = self.fuel_web.get_public_vip(cluster_id)
        os_conn = os_actions.OpenStackActions(
            os_ip, SERVTEST_USERNAME,
            SERVTEST_PASSWORD,
            SERVTEST_TENANT)

        # Create security group with rules for ssh and ping
        security_group = os_conn.create_sec_group_for_ssh()

        self.show_step(2)
        net = self.networks[0]
        net_1 = os_conn.create_network(network_name=net['name'])['network']

        subnet = os_conn.create_subnet(
            subnet_name=net['subnets'][0]['name'],
            network_id=net_1['id'],
            cidr=net['subnets'][0]['cidr'])

        logger.info("Check network was created.")
        assert_true(os_conn.get_network(net_1['name'])['id'] == net_1['id'])

        logger.info("Add net_1 to default router")
        router = os_conn.get_router(os_conn.get_network(self.ext_net_name))
        os_conn.add_router_interface(router_id=router["id"],
                                     subnet_id=subnet["id"])

        self.show_step(3)
        self.show_step(4)
        instances = openstack.create_instances(
            os_conn=os_conn,
            nics=[{'net-id': net_1['id']}],
            vm_count=1,
            security_groups=[security_group.name])
        openstack.verify_instance_state(os_conn)

        ports = os_conn.neutron.list_ports()['ports']
        fips = openstack.create_and_assign_floating_ips(os_conn, instances)

        inst_ips = [os_conn.get_nova_instance_ip(i, net_name=net_1['name'])
                    for i in instances]
        inst_ports = [p for p in ports
                      if p['fixed_ips'][0]['ip_address'] in inst_ips]

        self.show_step(5)
        _body = {'port': {'admin_state_up': False}}
        for port in inst_ports:
            os_conn.neutron.update_port(port=port['id'], body=_body)

        self.show_step(6)
        try:
            openstack.ping_each_other(fips)
        except Exception as e:
            logger.info(e)
        else:
            fail('Ping is available between instances')

        self.show_step(7)
        _body = {'port': {'admin_state_up': True}}
        for port in inst_ports:
            os_conn.neutron.update_port(port=port['id'], body=_body)

        self.show_step(8)
        openstack.ping_each_other(fips, timeout=90)
示例#9
0
    def dvs_destructive_setup_2(self):
        """Verify that vmclusters migrate after reset controller.

        Scenario:
            1. Upload plugins to the master node.
            2. Install plugin.
            3. Configure cluster with 2 vcenter clusters.
            4. Add 3 node with controller role.
            5. Add 2 node with compute role.
            6. Configure vcenter.
            7. Deploy the cluster.
            8. Run smoke OSTF tests
            9. Launch instances. 1 per az. Assign floating ips.
            10. Make snapshot.

        Duration: 1.8 hours
        Snapshot: dvs_destructive_setup_2
        """
        self.show_step(1)
        self.env.revert_snapshot("ready_with_5_slaves")

        plugin.install_dvs_plugin(self.ssh_manager.admin_ip)

        self.show_step(2)
        cluster_id = self.fuel_web.create_cluster(name=self.__class__.__name__,
                                                  mode=DEPLOYMENT_MODE,
                                                  settings={
                                                      "net_provider":
                                                      'neutron',
                                                      "net_segment_type":
                                                      NEUTRON_SEGMENT_TYPE
                                                  })
        plugin.enable_plugin(cluster_id, self.fuel_web)

        self.show_step(3)
        self.show_step(4)
        self.fuel_web.update_nodes(
            cluster_id, {
                'slave-01': ['controller'],
                'slave-02': ['controller'],
                'slave-03': ['controller'],
                'slave-04': ['compute'],
                'slave-05': ['compute']
            })
        self.show_step(6)
        self.fuel_web.vcenter_configure(cluster_id, multiclusters=True)

        self.show_step(7)
        self.fuel_web.deploy_cluster_wait(cluster_id)

        self.show_step(8)
        self.fuel_web.run_ostf(cluster_id=cluster_id, test_sets=['smoke'])

        self.show_step(9)
        os_ip = self.fuel_web.get_public_vip(cluster_id)
        os_conn = os_actions.OpenStackActions(os_ip, SERVTEST_USERNAME,
                                              SERVTEST_PASSWORD,
                                              SERVTEST_TENANT)

        security_group = os_conn.create_sec_group_for_ssh()

        network = os_conn.nova.networks.find(label=self.inter_net_name)
        instances = openstack.create_instances(
            os_conn=os_conn,
            nics=[{
                'net-id': network.id
            }],
            vm_count=1,
            security_groups=[security_group.name])
        openstack.verify_instance_state(os_conn)
        openstack.create_and_assign_floating_ips(os_conn, instances)

        self.show_step(10)
        self.env.make_snapshot("dvs_destructive_setup_2", is_make=True)
示例#10
0
    def dvs_vcenter_bind_port(self):
        """Check abilities to bind port on DVS to VM, disable/enable this port.

        Scenario:
            1. Revert snapshot to dvs_vcenter_systest_setup.
            2. Create private networks net01 with subnet.
            3. Launch instance VM_1 in the net01 with
               image TestVM and flavor m1.micro in nova az.
            4. Launch instance VM_2 in the net01 with
               image TestVM-VMDK and flavor m1.micro in vcenter az.
            5. Disable sub_net port of instances.
            6. Check instances are not available.
            7. Enable sub_net port of all instances.
            8. Verify that instances communicate between each other.
               Send icmp ping between instances.

        Duration: 1,5 hours

        """
        self.show_step(1)
        self.env.revert_snapshot("dvs_vcenter_systest_setup")

        cluster_id = self.fuel_web.get_last_created_cluster()

        os_ip = self.fuel_web.get_public_vip(cluster_id)
        os_conn = os_actions.OpenStackActions(os_ip, SERVTEST_USERNAME,
                                              SERVTEST_PASSWORD,
                                              SERVTEST_TENANT)

        # Create security group with rules for ssh and ping
        security_group = os_conn.create_sec_group_for_ssh()

        self.show_step(2)
        net = self.networks[0]
        net_1 = os_conn.create_network(network_name=net['name'])['network']

        subnet = os_conn.create_subnet(subnet_name=net['subnets'][0]['name'],
                                       network_id=net_1['id'],
                                       cidr=net['subnets'][0]['cidr'])

        logger.info("Check network was created.")
        assert_true(os_conn.get_network(net_1['name'])['id'] == net_1['id'])

        logger.info("Add net_1 to default router")
        router = os_conn.get_router(os_conn.get_network(self.ext_net_name))
        os_conn.add_router_interface(router_id=router["id"],
                                     subnet_id=subnet["id"])

        self.show_step(3)
        self.show_step(4)
        instances = openstack.create_instances(
            os_conn=os_conn,
            nics=[{
                'net-id': net_1['id']
            }],
            vm_count=1,
            security_groups=[security_group.name])
        openstack.verify_instance_state(os_conn)

        ports = os_conn.neutron.list_ports()['ports']
        fips = openstack.create_and_assign_floating_ips(os_conn, instances)

        inst_ips = [
            os_conn.get_nova_instance_ip(i, net_name=net_1['name'])
            for i in instances
        ]
        inst_ports = [
            p for p in ports if p['fixed_ips'][0]['ip_address'] in inst_ips
        ]

        self.show_step(5)
        _body = {'port': {'admin_state_up': False}}
        for port in inst_ports:
            os_conn.neutron.update_port(port=port['id'], body=_body)

        self.show_step(6)
        try:
            openstack.ping_each_other(fips)
        except Exception as e:
            logger.info(e)
        else:
            fail('Ping is available between instances')

        self.show_step(7)
        _body = {'port': {'admin_state_up': True}}
        for port in inst_ports:
            os_conn.neutron.update_port(port=port['id'], body=_body)

        self.show_step(8)
        openstack.ping_each_other(fips, timeout=90)
    def dvs_regression(self):
        """Deploy cluster with plugin and vmware datastore backend.

        Scenario:
            1. Upload plugins to the master node
            2. Install plugin.
            3. Create cluster with vcenter.
            4. Add 3 node with controller role.
            5. Add 2 node with compute + ceph role.
            6. Add 1 node with compute-vmware + cinder vmware role.
            7. Deploy the cluster.
            8. Run OSTF.
            9. Create non default network.
            10. Create Security groups
            11. Launch instances with created network in nova and vcenter az.
            12. Attached created security groups to instances.
            13. Check connection between instances from different az.

        Duration: 1.8 hours
        """
        self.env.revert_snapshot("dvs_bvt")

        cluster_id = self.fuel_web.get_last_created_cluster()

        os_ip = self.fuel_web.get_public_vip(cluster_id)
        os_conn = os_actions.OpenStackActions(
            os_ip, SERVTEST_USERNAME,
            SERVTEST_PASSWORD,
            SERVTEST_TENANT)

        tenant = os_conn.get_tenant(SERVTEST_TENANT)
        # Create non default network with subnet.
        logger.info('Create network {}'.format(self.net_data[0].keys()[0]))
        network = os_conn.create_network(
            network_name=self.net_data[0].keys()[0],
            tenant_id=tenant.id)['network']

        subnet = os_conn.create_subnet(
            subnet_name=network['name'],
            network_id=network['id'],
            cidr=self.net_data[0][self.net_data[0].keys()[0]],
            ip_version=4)

        # Check that network are created.
        assert_true(
            os_conn.get_network(network['name'])['id'] == network['id']
        )
        # Add net_1 to default router
        router = os_conn.get_router(os_conn.get_network(self.ext_net_name))
        os_conn.add_router_interface(
            router_id=router["id"],
            subnet_id=subnet["id"])
        # Launch instance 2 VMs of vcenter and 2 VMs of nova
        # in the tenant network net_01
        openstack.create_instances(
            os_conn=os_conn, vm_count=1,
            nics=[{'net-id': network['id']}]
        )
        # Launch instance 2 VMs of vcenter and 2 VMs of nova
        # in the default network
        network = os_conn.nova.networks.find(label=self.inter_net_name)
        instances = openstack.create_instances(
            os_conn=os_conn, vm_count=1,
            nics=[{'net-id': network.id}])
        openstack.verify_instance_state(os_conn)

        # Create security groups SG_1 to allow ICMP traffic.
        # Add Ingress rule for ICMP protocol to SG_1
        # Create security groups SG_2 to allow TCP traffic 22 port.
        # Add Ingress rule for TCP protocol to SG_2
        sec_name = ['SG1', 'SG2']
        sg1 = os_conn.nova.security_groups.create(
            sec_name[0], "descr")
        sg2 = os_conn.nova.security_groups.create(
            sec_name[1], "descr")
        rulesets = [
            {
                # ssh
                'ip_protocol': 'tcp',
                'from_port': 22,
                'to_port': 22,
                'cidr': '0.0.0.0/0',
            },
            {
                # ping
                'ip_protocol': 'icmp',
                'from_port': -1,
                'to_port': -1,
                'cidr': '0.0.0.0/0',
            }
        ]
        os_conn.nova.security_group_rules.create(
            sg1.id, **rulesets[0]
        )
        os_conn.nova.security_group_rules.create(
            sg2.id, **rulesets[1]
        )
        # Remove default security group and attach SG_1 and SG2 to VMs
        srv_list = os_conn.get_servers()
        for srv in srv_list:
            srv.remove_security_group(srv.security_groups[0]['name'])
            srv.add_security_group(sg1.id)
            srv.add_security_group(sg2.id)
        time.sleep(20)  # need wait to update rules on dvs
        fip = openstack.create_and_assign_floating_ips(os_conn, instances)
        # Check ping between VMs
        controller = self.fuel_web.get_nailgun_primary_node(
            self.env.d_env.nodes().slaves[0]
        )
        with self.fuel_web.get_ssh_for_node(controller.name) as ssh_controller:
            openstack.check_connection_vms(
                os_conn, fip, remote=ssh_controller,
                command='pingv4')
    def dvs_vcenter_bind_port(self):
        """Check abilities to bind port on DVS to VM, disable/enable this port.

        Scenario:
            1. Revert snapshot to dvs_vcenter_destructive_setup
            2. Create private networks net01 with sunet.
            3. Launch instances VM_1 and VM_2 in the net01
               with image TestVM and flavor m1.micro in nova az.
            4. Launch instances VM_3 and VM_4 in the net01
               with image TestVM-VMDK and flavor m1.micro in nova az.
            4. Bind sub_net port of instances.
            5. Check instances are not available.
            6. Enable sub_net port of all instances.
            7. Verify that instances should communicate between each other.
               Send icmp ping between instances.


        Duration: 1,5 hours

        """
        self.env.revert_snapshot("dvs_vcenter_systest_setup")

        cluster_id = self.fuel_web.get_last_created_cluster()

        # Create new network
        os_ip = self.fuel_web.get_public_vip(cluster_id)
        os_conn = os_actions.OpenStackActions(os_ip, SERVTEST_USERNAME,
                                              SERVTEST_PASSWORD,
                                              SERVTEST_TENANT)

        # create security group with rules for ssh and ping
        security_group = os_conn.create_sec_group_for_ssh()

        logger.info("Create non default network with subnet.")
        logger.info('Create network {}'.format(self.net_data[0].keys()[0]))
        network = os_conn.create_network(
            network_name=self.net_data[0].keys()[0])['network']

        subnet = os_conn.create_subnet(
            subnet_name=network['name'],
            network_id=network['id'],
            cidr=self.net_data[0][self.net_data[0].keys()[0]])

        logger.info("Check that network are created.")
        assert_true(
            os_conn.get_network(network['name'])['id'] == network['id'])

        logger.info("Add net_1 to default router")
        router = os_conn.get_router(os_conn.get_network(self.ext_net_name))
        os_conn.add_router_interface(router_id=router["id"],
                                     subnet_id=subnet["id"])

        #  Launch instance VM_1 and VM_2
        instances = openstack.create_instances(
            os_conn=os_conn,
            nics=[{
                'net-id': network['id']
            }],
            vm_count=1,
            security_groups=[security_group.name])
        openstack.verify_instance_state(os_conn)

        ports = os_conn.neutron.list_ports()['ports']
        floating_ip = openstack.create_and_assign_floating_ips(
            os_conn, instances)
        instance_ports = []
        for instance in instances:
            instance_addr = os_conn.get_nova_instance_ip(
                instance, net_name=network['name'])
            for port in ports:
                port_addr = port['fixed_ips'][0]['ip_address']
                if instance_addr == port_addr:
                    instance_ports.append(port)
        for port in instance_ports:
            os_conn.neutron.update_port(port['id'],
                                        {'port': {
                                            'admin_state_up': False
                                        }})

        controller = self.fuel_web.get_nailgun_primary_node(
            self.env.d_env.nodes().slaves[0])
        with self.fuel_web.get_ssh_for_node(controller.name) as ssh_controller:
            # Verify that not connection to instances
            try:
                openstack.check_connection_vms(os_conn,
                                               floating_ip,
                                               remote=ssh_controller,
                                               command='pingv4')
            except Exception as e:
                logger.info(str(e))

            # Enable sub_net ports of instances
            for port in instance_ports:
                os_conn.neutron.update_port(port['id'],
                                            {'port': {
                                                'admin_state_up': True
                                            }})

                instance.reboot()
                wait(lambda: os_conn.get_instance_detail(instance).status ==
                     "ACTIVE",
                     timeout=300)

            time.sleep(60)  # need time after reboot to get ip by instance

            # Verify that instances should communicate between each other.
            # Send icmp ping between instances
            openstack.check_connection_vms(os_conn,
                                           floating_ip,
                                           remote=ssh_controller,
                                           command='pingv4')
示例#13
0
    def dvs_regression(self):
        """Deploy cluster with plugin and vmware datastore backend.

        Scenario:
            1. Upload plugins to the master node
            2. Install plugin.
            3. Create cluster with vcenter.
            4. Add 3 node with controller role.
            5. Add 2 node with compute + ceph role.
            6. Add 1 node with compute-vmware + cinder vmware role.
            7. Deploy the cluster.
            8. Run OSTF.
            9. Create non default network.
            10. Create Security groups
            11. Launch instances with created network in nova and vcenter az.
            12. Attached created security groups to instances.
            13. Check connection between instances from different az.

        Duration: 1.8 hours
        """
        self.env.revert_snapshot("dvs_bvt")

        cluster_id = self.fuel_web.get_last_created_cluster()

        os_ip = self.fuel_web.get_public_vip(cluster_id)
        os_conn = os_actions.OpenStackActions(os_ip, SERVTEST_USERNAME,
                                              SERVTEST_PASSWORD,
                                              SERVTEST_TENANT)

        tenant = os_conn.get_tenant(SERVTEST_TENANT)
        # Create non default network with subnet.
        logger.info('Create network {}'.format(self.net_data[0].keys()[0]))
        network = os_conn.create_network(
            network_name=self.net_data[0].keys()[0],
            tenant_id=tenant.id)['network']

        subnet = os_conn.create_subnet(
            subnet_name=network['name'],
            network_id=network['id'],
            cidr=self.net_data[0][self.net_data[0].keys()[0]],
            ip_version=4)

        # Check that network are created.
        assert_true(
            os_conn.get_network(network['name'])['id'] == network['id'])
        # Add net_1 to default router
        router = os_conn.get_router(os_conn.get_network(self.ext_net_name))
        os_conn.add_router_interface(router_id=router["id"],
                                     subnet_id=subnet["id"])
        # Launch instance 2 VMs of vcenter and 2 VMs of nova
        # in the tenant network net_01
        openstack.create_instances(os_conn=os_conn,
                                   vm_count=1,
                                   nics=[{
                                       'net-id': network['id']
                                   }])
        # Launch instance 2 VMs of vcenter and 2 VMs of nova
        # in the default network
        network = os_conn.nova.networks.find(label=self.inter_net_name)
        instances = openstack.create_instances(os_conn=os_conn,
                                               vm_count=1,
                                               nics=[{
                                                   'net-id': network.id
                                               }])
        openstack.verify_instance_state(os_conn)

        # Create security groups SG_1 to allow ICMP traffic.
        # Add Ingress rule for ICMP protocol to SG_1
        # Create security groups SG_2 to allow TCP traffic 22 port.
        # Add Ingress rule for TCP protocol to SG_2
        sec_name = ['SG1', 'SG2']
        sg1 = os_conn.nova.security_groups.create(sec_name[0], "descr")
        sg2 = os_conn.nova.security_groups.create(sec_name[1], "descr")
        rulesets = [
            {
                # ssh
                'ip_protocol': 'tcp',
                'from_port': 22,
                'to_port': 22,
                'cidr': '0.0.0.0/0',
            },
            {
                # ping
                'ip_protocol': 'icmp',
                'from_port': -1,
                'to_port': -1,
                'cidr': '0.0.0.0/0',
            }
        ]
        os_conn.nova.security_group_rules.create(sg1.id, **rulesets[0])
        os_conn.nova.security_group_rules.create(sg2.id, **rulesets[1])
        # Remove default security group and attach SG_1 and SG2 to VMs
        srv_list = os_conn.get_servers()
        for srv in srv_list:
            srv.remove_security_group(srv.security_groups[0]['name'])
            srv.add_security_group(sg1.id)
            srv.add_security_group(sg2.id)
        time.sleep(20)  # need wait to update rules on dvs
        fip = openstack.create_and_assign_floating_ips(os_conn, instances)
        # Check ping between VMs
        controller = self.fuel_web.get_nailgun_primary_node(
            self.env.d_env.nodes().slaves[0])
        with self.fuel_web.get_ssh_for_node(controller.name) as ssh_controller:
            openstack.check_connection_vms(os_conn,
                                           fip,
                                           remote=ssh_controller,
                                           command='pingv4')