def test_server_boot_w_ipv6_network_id(self):
        """
        @summary: Booting a server with network id from a network with an
                  IPv6 subnet
        """
        network = self.create_network()
        subnet = self.create_subnet(network_id=network.id, ip_version=6)

        network_ids = [self.public_network_id, self.service_network_id,
                       network.id]

        server = self.create_test_server(network_ids=network_ids)

        server_persona = ServerPersona(
            server=server, pnet=True, snet=True, inet=True, network=network,
            subnetv4=None, portv4=None, subnetv6=subnet, portv6=None,
            inet_port_count=1, snet_port_count=1, pnet_port_count=1,
            inet_fix_ipv4_count=0, inet_fix_ipv6_count=1,
            snet_fix_ipv4_count=1, snet_fix_ipv6_count=0,
            pnet_fix_ipv4_count=1, pnet_fix_ipv6_count=1)

        # Setting the isolated network port with updated device owner
        server_persona.portv6 = server_persona.inet_ports[0]

        self.assertServerPersonaNetworks(server_persona)
        self.assertServerPersonaPorts(server_persona)
        self.assertServerPersonaFixedIps(server_persona)
    def setUpClass(cls):
        super(TestBFVConnectivity, cls).setUpClass()
        network_name = 'network_{0}'.format(cls.NAMES_PREFIX)
        cls._create_keypair()
        cls.delete_keypairs.append(cls.keypair.name)
        network, subnet, port = (cls.net.behaviors.create_network_subnet_port(
            name=network_name))
        cls.delete_ports.append(port.id)
        cls.delete_networks.append(network.id)
        cls.delete_subnets.append(subnet.id)

        server1 = cls.create_server(key_name=cls.keypair.name,
                                    networks=[{
                                        'uuid': cls.public_network_id
                                    }, {
                                        'uuid': cls.service_network_id
                                    }, {
                                        'uuid': network.id
                                    }])
        server2 = cls.create_server(key_name=cls.keypair.name,
                                    networks=[{
                                        'uuid': cls.public_network_id
                                    }, {
                                        'uuid': cls.service_network_id
                                    }, {
                                        'uuid': network.id
                                    }])

        # Defining the server personas
        cls.sp1 = ServerPersona(server=server1,
                                pnet=True,
                                snet=True,
                                inet=True,
                                network=network,
                                keypair=cls.keypair,
                                ssh_username='******')
        cls.sp2 = ServerPersona(server=server2,
                                pnet=True,
                                snet=True,
                                inet=True,
                                network=network,
                                keypair=cls.keypair,
                                ssh_username='******')
        server_ids = [cls.sp1.server.id, cls.sp2.server.id]
        cls.delete_servers.extend(server_ids)

        cls._transfer_private_key_to_vm(cls.sp1.remote_client.ssh_client,
                                        cls.keypair.private_key,
                                        cls.PRIVATE_KEY_PATH)
        cls._transfer_private_key_to_vm(cls.sp2.remote_client.ssh_client,
                                        cls.keypair.private_key,
                                        cls.PRIVATE_KEY_PATH)
 def _remove_all_ips(self, server, port_type, ini_ips_count):
     """
     Tries to remove all network IPs from a server and verifies
     that the last IP of a network can NOT be removed
     """
     persona_args = {
         "server": self.server,
         "keypair": self.keypair,
         "pnet": True,
         "snet": True,
         "inet": True,
         "pnet_fix_ipv4_count": ini_ips_count,
         "snet_fix_ipv4_count": ini_ips_count,
         "inet_fix_ipv4_count": ini_ips_count,
         "network": self.network,
         "ssh_username": '******'
     }
     if port_type == self.pub_net_id:
         persona_args["pnet_fix_ipv4_count"] = self.FIXED_IPS_TO_ADD + 1
         server_persona = ServerPersona(**persona_args)
         ips = server_persona.pnet_fix_ipv4
         ip_count = server_persona.pnet_fix_ipv4_count
     if port_type == self.pri_net_id:
         persona_args["snet_fix_ipv4_count"] = self.FIXED_IPS_TO_ADD + 1
         server_persona = ServerPersona(**persona_args)
         ips = server_persona.snet_fix_ipv4
         ip_count = server_persona.snet_fix_ipv4_count
     if port_type == self.iso_net_id:
         persona_args["inet_fix_ipv4_count"] = self.FIXED_IPS_TO_ADD + 1
         server_persona = ServerPersona(**persona_args)
         ips = server_persona.inet_fix_ipv4
         ip_count = server_persona.inet_fix_ipv4_count
     # Try to remove all IPv4 IPs
     for ip_to_remove in ips:
         removed_ip_response = self.servers_client.\
             remove_fixed_ip(self.server.id, ip_to_remove)
         ip_count -= 1
         if ip_count >= 1:
             self.assertEqual(removed_ip_response.status_code,
                              NeutronResponseCodes.REMOVE_FIXED_IP,
                              msg=self.rem_msg.format(
                                  port_type, self.server.id,
                                  removed_ip_response))
         else:
             msg = ('Tried to remove last IP of {0} network in server {1} '
                    'Unexpected Response: {2}'.format(
                        port_type, server.id,
                        removed_ip_response.status_code))
             self.assertEqual(removed_ip_response.status_code,
                              NeutronResponseCodes.REMOVE_FIXED_IP, msg)
             self.assertServerPersonaFixedIps(self.server_persona)
Пример #4
0
    def _register_server(self, server, iso_network):
        """
        Registers the server in the topology for topology management and
        report tracking purposes.

        :param server: Server Model Object
        :param iso_network: Isolated Network Model Object

        :return: server id
        """

        # Register the server (using the server id)
        self.servers[server.id] = {}
        self.servers[server.id][self.SERVER] = server

        # Make sure server is registered to be cleaned up...
        if server.id not in self.delete_servers:
            self.delete_servers.append(server.id)

        # Build a network persona for the server (stored by server_id)
        self.servers[server.id][self.PERSONA] = ServerPersona(
            server=server,
            network=iso_network,
            inet_fix_ipv4_count=1,
            inet=True)
        self.fixture_log.debug(self.servers[server.id][self.PERSONA])

        # Build a proxy_mgr (allows easy access to the server to execute
        # commands from that server) - stored by server_id.
        proxy = NetworkProxyMgr(use_proxy=True)
        proxy.set_proxy_server(server)
        self.servers[server.id][self.PROXY] = proxy

        return server.id
 def setUpClass(cls):
     super(TestConnectivity, cls).setUpClass()
     network_name = 'network_1_{0}'.format(cls.NAMES_PREFIX)
     cls.network1 = cls.create_server_network(name=network_name, ipv4=True)
     cls.delete_networks.append(cls.network1.id)
     keypair_name = 'key_{0}'.format(cls.NAMES_PREFIX)
     keypair = cls.create_keypair(name=keypair_name)
     cls.delete_keypairs.append(keypair.name)
     svr_name_1 = 'svr_1_{0}'.format(cls.NAMES_PREFIX)
     network_ids = [
         cls.public_network_id, cls.service_network_id, cls.network1.id
     ]
     cls.server1 = cls.create_test_server(name=svr_name_1,
                                          key_name=keypair.name,
                                          network_ids=network_ids,
                                          active_server=False)
     cls.sp1 = ServerPersona(server=cls.server1,
                             pnet=True,
                             snet=True,
                             inet=True,
                             network=cls.network1,
                             keypair=keypair,
                             ssh_username='******')
     network_name = 'network_2_{0}'.format(cls.NAMES_PREFIX)
     cls.network2 = cls.create_server_network(name=network_name, ipv4=True)
     svr_name_2 = 'svr_2_{0}'.format(cls.NAMES_PREFIX)
     network_ids = [cls.public_network_id]
     cls.server2 = cls.create_test_server(name=svr_name_2,
                                          key_name=keypair.name,
                                          network_ids=network_ids,
                                          active_server=False)
     cls.sp2 = ServerPersona(server=cls.server2,
                             pnet=True,
                             snet=False,
                             inet=False,
                             network=cls.network2,
                             keypair=keypair,
                             ssh_username='******')
     server_ids = [cls.sp1.server.id, cls.sp2.server.id]
     cls.delete_servers.extend(server_ids)
     cls._transfer_private_key_to_vm(cls.sp1.remote_client.ssh_client,
                                     keypair.private_key,
                                     cls.PRIVATE_KEY_PATH)
     cls._transfer_private_key_to_vm(cls.sp2.remote_client.ssh_client,
                                     keypair.private_key,
                                     cls.PRIVATE_KEY_PATH)
Пример #6
0
    def setUpClass(cls):
        super(TestConnectivity, cls).setUpClass()
        network_name = 'network_{0}'.format(cls.NAMES_PREFIX)
        svr_name_1 = 'svr_1_{0}'.format(cls.NAMES_PREFIX)
        svr_name_2 = 'svr_2_{0}'.format(cls.NAMES_PREFIX)
        cls._create_keypair()
        cls.delete_keypairs.append(cls.keypair.name)
        network, subnet, port = (cls.net.behaviors.create_network_subnet_port(
            name=network_name))
        cls.delete_ports.append(port.id)
        cls.delete_networks.append(network.id)
        cls.delete_subnets.append(subnet.id)
        servers = cls.net.behaviors.create_multiple_servers(
            names=[svr_name_1, svr_name_2],
            pnet=True,
            snet=True,
            keypair_name=cls.keypair.name,
            networks=[network.id])
        svr_names = servers.keys()
        svr_names.sort()

        # Defining the server personas
        cls.sp1 = ServerPersona(server=servers[svr_names[0]],
                                pnet=True,
                                snet=True,
                                inet=True,
                                network=network,
                                keypair=cls.keypair,
                                ssh_username='******')
        cls.sp2 = ServerPersona(server=servers[svr_names[1]],
                                pnet=True,
                                snet=True,
                                inet=True,
                                network=network,
                                keypair=cls.keypair,
                                ssh_username='******')

        server_ids = [cls.sp1.server.id, cls.sp2.server.id]
        cls.delete_servers.extend(server_ids)
        cls._transfer_private_key_to_vm(cls.sp1.remote_client.ssh_client,
                                        cls.keypair.private_key,
                                        cls.PRIVATE_KEY_PATH)
        cls._transfer_private_key_to_vm(cls.sp2.remote_client.ssh_client,
                                        cls.keypair.private_key,
                                        cls.PRIVATE_KEY_PATH)
    def setUpClass(cls):
        super(TestFixedIPsMultiple, cls).setUpClass()
        network_name = 'network_{0}'.format(cls.NAMES_PREFIX)
        cls.network = cls.create_server_network(name=network_name, ipv4=True)
        cls.delete_networks.append(cls.network.id)
        keypair_name = 'key_{0}'.format(cls.NAMES_PREFIX)
        cls.keypair = cls.create_keypair(name=keypair_name)
        cls.delete_keypairs.append(cls.keypair.name)
        svr_name = 'svr_{0}'.format(cls.NAMES_PREFIX)
        network_ids = [
            cls.public_network_id, cls.service_network_id, cls.network.id
        ]
        cls.server = cls.create_test_server(name=svr_name,
                                            key_name=cls.keypair.name,
                                            network_ids=network_ids,
                                            active_server=False)
        cls.server_persona = ServerPersona(server=cls.server,
                                           pnet=True,
                                           snet=True,
                                           inet=True,
                                           pnet_fix_ipv4_count=1,
                                           snet_fix_ipv4_count=1,
                                           inet_fix_ipv4_count=1,
                                           network=cls.network,
                                           keypair=cls.keypair,
                                           ssh_username='******')
        server_ids = [cls.server_persona.server.id]
        cls.delete_servers.extend(server_ids)

        cls.pub_net_id = cls.public_network_id
        cls.pri_net_id = cls.service_network_id
        cls.iso_net_id = cls.network.id
        cls.initial_pub_ip = cls.server_persona.pnet_fix_ipv4
        cls.initial_pri_ip = cls.server_persona.snet_fix_ipv4
        cls.initial_iso_ip = cls.server_persona.inet_fix_ipv4
        # Initial IPv4 counts, update as needed if using a specific server
        cls.ini_ips_count = 1
        # Multiple fixed IPs to add
        cls.FIXED_IPS_TO_ADD = cls.net.config.multiple_fixed_ips_to_add

        admin_user = ComputeAdminUserConfig()
        compute_admin_endpoint = ComputeAdminEndpointConfig()
        auth_endpoint_config = ComputeAdminAuthConfig()
        access_data = AuthProvider.get_access_data(auth_endpoint_config,
                                                   admin_user)
        compute_service = access_data.get_service(
            compute_admin_endpoint.compute_endpoint_name)
        url = compute_service.get_endpoint(
            compute_admin_endpoint.region).public_url
        cls.servers_client = ServersClient(url, access_data.token.id_, 'json',
                                           'json')

        cls.add_msg = ('Unable to add a {0} network fixed IP to server {1} '
                       'Response: {2}')
        cls.rem_msg = ('Unable to remove a {0} network fixed IP of server {1} '
                       'Response: {2}')
Пример #8
0
    def test_server_boot_w_ipv6_network_id(self):
        """
        @summary: Booting a server with network id from a network with an
                  IPv6 subnet
        """
        network = self.create_network()
        subnet = self.create_subnet(network_id=network.id, ip_version=6)

        network_ids = [
            self.public_network_id, self.service_network_id, network.id
        ]

        server = self.create_test_server(network_ids=network_ids)

        server_persona = ServerPersona(server=server,
                                       pnet=True,
                                       snet=True,
                                       inet=True,
                                       network=network,
                                       subnetv4=None,
                                       portv4=None,
                                       subnetv6=subnet,
                                       portv6=None,
                                       inet_port_count=1,
                                       snet_port_count=1,
                                       pnet_port_count=1,
                                       inet_fix_ipv4_count=0,
                                       inet_fix_ipv6_count=1,
                                       snet_fix_ipv4_count=1,
                                       snet_fix_ipv6_count=0,
                                       pnet_fix_ipv4_count=1,
                                       pnet_fix_ipv6_count=1)

        # Setting the isolated network port with updated device owner
        server_persona.portv6 = server_persona.inet_ports[0]

        self.assertServerPersonaNetworks(server_persona)
        self.assertServerPersonaPorts(server_persona)
        self.assertServerPersonaFixedIps(server_persona)
    def test_server_boot_w_ipv6_port_id(self):
        """
        @summary: Booting a server with port_id from an IPv6 port
        """
        network = self.create_network()
        subnet = self.create_subnet(network_id=network.id, ip_version=6)
        port = self.create_port(network_id=network.id)

        port_ids = [port.id]
        network_ids = [self.public_network_id, self.service_network_id]

        server = self.create_test_server(network_ids=network_ids,
                                         port_ids=port_ids)

        server_persona = ServerPersona(server=server,
                                       pnet=True,
                                       snet=True,
                                       inet=True,
                                       network=network,
                                       subnetv4=None,
                                       portv4=None,
                                       subnetv6=subnet,
                                       portv6=port,
                                       inet_port_count=1,
                                       snet_port_count=1,
                                       pnet_port_count=1,
                                       inet_fix_ipv4_count=0,
                                       inet_fix_ipv6_count=1,
                                       snet_fix_ipv4_count=1,
                                       snet_fix_ipv6_count=0,
                                       pnet_fix_ipv4_count=1,
                                       pnet_fix_ipv6_count=1)

        self.assertServerPersonaNetworks(server_persona)
        self.assertServerPersonaPorts(server_persona)
        self.assertServerPersonaFixedIps(server_persona)
    def setUpClass(cls):
        super(TestFixedIPsConnectivity, cls).setUpClass()
        network_name = 'network_{0}'.format(cls.NAMES_PREFIX)
        cls.network = cls.create_server_network(name=network_name, ipv4=True)
        cls.delete_networks.append(cls.network.id)
        keypair_name = 'key_{0}'.format(cls.NAMES_PREFIX)
        cls.keypair = cls.create_keypair(name=keypair_name)
        cls.delete_keypairs.append(cls.keypair.name)
        svr_name_1 = 'svr_1_{0}'.format(cls.NAMES_PREFIX)
        svr_name_2 = 'svr_2_{0}'.format(cls.NAMES_PREFIX)
        network_ids = [
            cls.public_network_id, cls.service_network_id, cls.network.id
        ]
        cls.server1 = cls.create_test_server(name=svr_name_1,
                                             key_name=cls.keypair.name,
                                             network_ids=network_ids,
                                             active_server=False)
        cls.server2 = cls.create_test_server(name=svr_name_2,
                                             key_name=cls.keypair.name,
                                             network_ids=network_ids,
                                             active_server=False)
        cls.servers = [cls.server1, cls.server2]

        cls.FIXED_IPS_TO_ADD = cls.net.config.fixed_ips_to_add
        cls.PNET_FIX_IPv4_COUNT = cls.FIXED_IPS_TO_ADD + 1
        cls.SNET_FIX_IPv4_COUNT = cls.FIXED_IPS_TO_ADD + 1
        cls.INET_FIX_IPv4_COUNT = cls.FIXED_IPS_TO_ADD + 1
        cls.TOTAL_INITIAL_IPS_SERVER = 3
        cls.TOTAL_NETWORKS_ATTACHED_TO_SERVER = 3
        cls.TOTAL_IPS_SERVER = cls.TOTAL_INITIAL_IPS_SERVER + \
            (cls.FIXED_IPS_TO_ADD * cls.TOTAL_NETWORKS_ATTACHED_TO_SERVER)
        # Add fixed IPs to servers
        for server in cls.servers:
            cls.add_fixed_ips_network(server,
                                      cls.public_network_id,
                                      number_fixed_ips=cls.FIXED_IPS_TO_ADD)
            cls.add_fixed_ips_network(server,
                                      cls.service_network_id,
                                      number_fixed_ips=cls.FIXED_IPS_TO_ADD)
            cls.add_fixed_ips_network(server,
                                      cls.network.id,
                                      number_fixed_ips=cls.FIXED_IPS_TO_ADD)

        cls.server_persona1 = ServerPersona(
            server=cls.server1,
            pnet=True,
            snet=True,
            inet=True,
            pnet_fix_ipv4_count=cls.PNET_FIX_IPv4_COUNT,
            snet_fix_ipv4_count=cls.SNET_FIX_IPv4_COUNT,
            inet_fix_ipv4_count=cls.INET_FIX_IPv4_COUNT,
            network=cls.network,
            keypair=cls.keypair,
            ssh_username='******')
        cls.server_persona2 = ServerPersona(
            server=cls.server2,
            pnet=True,
            snet=True,
            inet=True,
            pnet_fix_ipv4_count=cls.PNET_FIX_IPv4_COUNT,
            snet_fix_ipv4_count=cls.SNET_FIX_IPv4_COUNT,
            inet_fix_ipv4_count=cls.INET_FIX_IPv4_COUNT,
            network=cls.network,
            keypair=cls.keypair,
            ssh_username='******')
        server_ids = [
            cls.server_persona1.server.id, cls.server_persona2.server.id
        ]
        cls.delete_servers.extend(server_ids)

        cls._transfer_private_key_to_vm(
            cls.server_persona1.remote_client.ssh_client,
            cls.keypair.private_key, cls.PRIVATE_KEY_PATH)
        cls._transfer_private_key_to_vm(
            cls.server_persona2.remote_client.ssh_client,
            cls.keypair.private_key, cls.PRIVATE_KEY_PATH)
Пример #11
0
    def _build_hub_router(self, network_spokes):
        """
        Build the hub router (host) with each spoke's gateway configured as
        a network interface on the router.

        :param network_spokes: [List] List of iso_subnets that define each
            spoke

        :return: VM server model representing the hub router
        """
        port_ids = []
        hub_name = 'HUB_{spokes}_{run_id}'.format(spokes=len(network_spokes),
                                                  run_id=self.RUN_ID)
        hub = {}

        # Iterate across spoke (subnets), and configure each GW IP as an
        # interface on the 'hub' router.
        for spoke in network_spokes:
            network_id = spoke.network_id
            fixed_ips = [{
                'ip_address': spoke.gateway_ip,
                'subnet_id': spoke.id
            }]
            port_resp = self.net.ports.behaviors.create_port(
                network_id=network_id,
                admin_state_up=True,
                fixed_ips=fixed_ips)

            self.delete_ports.append(port_resp.response.entity.id)
            port_ids.append(port_resp.response.entity.id)

        # Add public and service networks to the hub router
        attached_networks = [self.public_network_id, self.service_network_id]

        hub_svr = self.net.behaviors.create_networking_server(
            name=hub_name,
            admin_pass=self.ADMIN_PASS,
            network_ids=attached_networks,
            port_ids=port_ids)
        self.delete_servers.append(hub_svr.entity.id)

        # Store HUB server information
        hub[TopologyFixtureRoutines.SERVER] = hub_svr.entity

        hub_persona = ServerPersona(server=hub_svr.entity)
        hub[TopologyFixtureRoutines.PERSONA] = hub_persona

        proxy = NetworkProxyMgr(use_proxy=False, debug=True)
        proxy.set_proxy_server(hub_svr.entity)
        hub[TopologyFixtureRoutines.PROXY] = proxy

        self.fixture_log.debug(
            "HUB INTERFACE INFO (PARTIAL)\n{0}".format(hub_persona))

        # Wait for VM's public network to come online by pinging the server's
        # public interface
        attempt = 0
        max_attempts = 10
        hub_available = False
        while not hub_available and attempt < max_attempts:
            attempt += 1
            self.fixture_log.debug(
                'Verifying hub router is online. Attempt: {0} of {1}'.format(
                    attempt, max_attempts))
            try:
                hub_available = proxy.ping(hub_persona.pnet_fix_ipv4[0])

            except Exception as err:
                self.fixture_log.info('PING EXCEPTION: {0}'.format(err))
                hub_available = False

            if not hub_available:
                time.sleep(5)

        if attempt >= max_attempts:
            self.assertClassSetupFailure(
                'Hub router (hub & spoke topology) never came online. Unable '
                'to proceed.')

        # Give the SSH daemon time to start up. The network is active,
        # but SSH is unstable at this point in the hub's provisioning.
        time.sleep(self.SSH_PROVISION_DELAY)

        # Enable the hub to do basic routing
        self.enable_ip_forwarding(hub)

        return hub
Пример #12
0
    def setUpClass(cls):
        super(AutoPortUpdateTest, cls).setUpClass()

        cls.ICMP = 'icmp'
        cls.TCP = 'tcp'
        cls.UDP = 'udp'
        cls.connection = 'connection'
        cls.ingress_rule_request = 'ingress_rule_request'
        cls.job_id = 'job_id'

        # Defining resource names
        test_label = 'auto_port_update'
        # sg with initial sg ping IPv4 and tcp 22 rules
        sg_name_1 = 'sg_1_{0}'.format(test_label)
        # sg without initial sg rules
        sg_name_2 = 'sg_2_{0}'.format(test_label)
        # server without sg
        svr_name_1 = 'svr_1_{0}'.format(test_label)
        # server with initial sg rules
        svr_name_2 = 'svr_2_{0}'.format(test_label)
        # server without initial sg rules
        svr_name_3 = 'svr_3_{0}'.format(test_label)
        keypair_name = 'key_{0}'.format(test_label)

        keypair = cls.net.behaviors.create_keypair(
            name=keypair_name, raise_exception=True)
        cls.delete_keypairs.append(keypair.name)

        log_msg = '{0} keypair created'.format(keypair.name)
        cls.fixture_log.info(log_msg)

        # Creating isolated network, subnet and port
        network, subnet, port = (
            cls.net.behaviors.create_network_subnet_port())
        cls.delete_ports.append(port.id)
        cls.delete_networks.append(network.id)

        log_msg = ('Created network: {0}\n'
                   'subnet: {1}\n'
                   'port: {2}').format(network.id, subnet.id, port.id)
        cls.fixture_log.info(log_msg)

        svrs = cls.net.behaviors.create_multiple_servers(
            names=[svr_name_1, svr_name_2, svr_name_3],
            keypair_name=keypair.name, networks=[network.id])
        svr_names = svrs.keys()
        svr_names.sort()

        log_msg = 'Created servers: {0}'.format(svr_names)
        cls.fixture_log.info(log_msg)

        # Defining the server personas
        cls.sp1 = ServerPersona(
            server=svrs[svr_names[0]], inet_port_count=1,
            inet_fix_ipv4_count=1, network=network, keypair=keypair,
            ssh_username='******')
        cls.sp2 = ServerPersona(
            server=svrs[svr_names[1]], inet_port_count=1,
            inet_fix_ipv4_count=1, network=network, keypair=keypair,
            ssh_username='******')
        cls.sp3 = ServerPersona(
            server=svrs[svr_names[2]], inet_port_count=1,
            inet_fix_ipv4_count=1, network=network, keypair=keypair,
            ssh_username='******')

        server_ids = [cls.sp1.server.id, cls.sp2.server.id, cls.sp3.server.id]
        cls.delete_servers.extend(server_ids)

        log_msg = 'Created server personas'
        cls.fixture_log.info(log_msg)
        cls.fixture_log.info(cls.sp1)
        cls.fixture_log.info(cls.sp2)
        cls.fixture_log.info(cls.sp3)

        # Create the SG w initial icmp/tcp rules for server 2
        sg = cls.sec.behaviors.create_security_group(
            name=sg_name_1, description='auto port update sg group')
        sg_id = sg.response.entity.id
        cls.delete_secgroups.append(sg_id)
        cls.sec_groups_s2 = [sg_id]

        log_msg = 'Created security group: {0}'.format(sg_id)
        cls.fixture_log.info(log_msg)

        icmp_ipv4_rules = dict(version=4, protocol=cls.ICMP,
                               ingress=True, egress=True)
        icmp_ipv6_rules = dict(version=6, protocol=cls.ICMP,
                               ingress=True, egress=True)
        tcp_ipv4_rules = dict(version=4, protocol=cls.TCP, ports=22,
                              ingress=True, egress=False)
        tcp_ipv6_rules = dict(version=6, protocol=cls.TCP, ports=22,
                              ingress=True, egress=False)
        security_rules = [icmp_ipv4_rules, icmp_ipv6_rules,
                          tcp_ipv4_rules, tcp_ipv6_rules]

        # Adding the rules to the Security Group for Server 2
        for rule in security_rules:
            rule.update(security_groups=cls.sec_groups_s2)
            resp = cls.sec.behaviors.add_rule(**rule)
            log_msg = 'Created {0} rules: {1}'.format(rule['protocol'], resp)
            cls.fixture_log.info(log_msg)

        port_types = [PortTypes.PUBLIC, PortTypes.SERVICE, PortTypes.ISOLATED]

        # Adding the Security Group to server 2 ports for IPv4 ping and SSH
        for port_type in port_types:
            resp = cls.sp2.add_security_groups_to_ports(
                port_type=port_type, security_group_ids=cls.sec_groups_s2)

            if not resp:
                msg = 'Unable to add SG {0} to server {1} port: {2}'.format(
                    sg_id, svr_name_2, port_type)
                cls.assertClassSetupFailure(msg)

        # Create an SG without any rules for server 3
        sg2 = cls.sec.behaviors.create_security_group(
            name=sg_name_2, description='auto port update sg group 2')
        sg2_id = sg2.response.entity.id
        cls.delete_secgroups.append(sg2_id)
        cls.sec_groups_s3 = [sg2_id]

        # Adding this group to server 3 - no connectivity should be available
        for port_type in port_types:
            resp = cls.sp3.add_security_groups_to_ports(
                port_type=port_type, security_group_ids=cls.sec_groups_s3)

            if not resp:
                msg = 'Unable to add SG {0} to server {1} port: {2}'.format(
                    sg2_id, svr_name_3, port_type)
                cls.assertClassSetupFailure(msg)

        # Port update data plane delay for the auto port update
        cls.data_plane_delay = cls.sec.config.data_plane_delay
        cls.data_plane_delay_msg = 'data plane delay {0}'.format(
            cls.data_plane_delay)
Пример #13
0
    def _test_add_remove_fixed_ip(self, port_type=None):
        # For initial IPs, assert the expected counts for IPv4
        self.assertServerPersonaFixedIps(self.server_persona)

        # Add an IP and assert the new counts for IPv4
        add_ip_response = self.servers_client.add_fixed_ip(
            self.server.id, port_type)
        self.assertEqual(add_ip_response.status_code,
                         NeutronResponseCodes.ADD_FIXED_IP,
                         msg=self.add_msg.format(port_type, self.server.id,
                                                 add_ip_response))
        if port_type == self.pub_net_id:
            server_persona = ServerPersona(server=self.server,
                                           pnet=True,
                                           snet=True,
                                           inet=True,
                                           pnet_fix_ipv4_count=2,
                                           snet_fix_ipv4_count=1,
                                           inet_fix_ipv4_count=1,
                                           network=self.network,
                                           keypair=self.keypair,
                                           ssh_username='******')
            # Get the added public IP address
            pub_ips = server_persona.pnet_fix_ipv4
            for ip in pub_ips:
                if ip != self.initial_pub_ip:
                    added_ip = ip
        if port_type == self.pri_net_id:
            server_persona = ServerPersona(server=self.server,
                                           pnet=True,
                                           snet=True,
                                           inet=True,
                                           pnet_fix_ipv4_count=1,
                                           snet_fix_ipv4_count=2,
                                           inet_fix_ipv4_count=1,
                                           network=self.network,
                                           keypair=self.keypair,
                                           ssh_username='******')
            # Get the added private IP address
            pri_ips = server_persona.snet_fix_ipv4
            for ip in pri_ips:
                if ip != self.initial_pri_ip:
                    added_ip = ip
        if port_type == self.iso_net_id:
            server_persona = ServerPersona(server=self.server,
                                           pnet=True,
                                           snet=True,
                                           inet=True,
                                           pnet_fix_ipv4_count=1,
                                           snet_fix_ipv4_count=1,
                                           inet_fix_ipv4_count=2,
                                           network=self.network,
                                           keypair=self.keypair,
                                           ssh_username='******')
            # Get the added isolated IP address
            iso_ips = server_persona.inet_fix_ipv4
            for ip in iso_ips:
                if ip != self.initial_iso_ip:
                    added_ip = ip
        self.assertServerPersonaFixedIps(server_persona)

        # Remove the added IP and assert the updated counts for IPv4
        removed_ip_response = self.servers_client.remove_fixed_ip(
            self.server.id, added_ip)
        self.assertEqual(removed_ip_response.status_code,
                         NeutronResponseCodes.REMOVE_FIXED_IP,
                         msg=self.rem_msg.format(port_type, self.server.id,
                                                 removed_ip_response))
        self.assertServerPersonaFixedIps(self.server_persona)
 def _test_add_remove_fixed_ip(self, port_type, number_fixed_ips,
                               ini_ips_count):
     # For initial IPs, assert the expected counts for IPv4
     self.assertServerPersonaFixedIps(self.server_persona)
     ip_count = ini_ips_count
     added_ips = []
     for _ in range(number_fixed_ips):
         # Add an IP and assert the new counts for IPv4
         add_ip_response = self.servers_client.add_fixed_ip(
             self.server.id, port_type)
         self.assertEqual(add_ip_response.status_code,
                          NeutronResponseCodes.ADD_FIXED_IP,
                          msg=self.add_msg.format(port_type, self.server.id,
                                                  add_ip_response))
         if port_type == self.pub_net_id:
             ip_count += 1
             server_persona = ServerPersona(
                 server=self.server,
                 pnet=True,
                 snet=True,
                 inet=True,
                 pnet_fix_ipv4_count=ip_count,
                 snet_fix_ipv4_count=ini_ips_count,
                 inet_fix_ipv4_count=ini_ips_count,
                 network=self.network,
                 keypair=self.keypair,
                 ssh_username='******')
             # Get the added public IP address and saving the added
             # ips for removing
             public_ips = server_persona.pnet_fix_ipv4
             for ip in public_ips:
                 if ip != self.initial_pub_ip[0] and ip not in added_ips:
                     added_ips.append(ip)
         elif port_type == self.pri_net_id:
             ip_count += 1
             server_persona = ServerPersona(
                 server=self.server,
                 pnet=True,
                 snet=True,
                 inet=True,
                 pnet_fix_ipv4_count=ini_ips_count,
                 snet_fix_ipv4_count=ip_count,
                 inet_fix_ipv4_count=ini_ips_count,
                 network=self.network,
                 keypair=self.keypair,
                 ssh_username='******')
             # Get the added private IP address and saving the added
             # ips for removing
             private_ips = server_persona.snet_fix_ipv4
             for ip in private_ips:
                 if ip != self.initial_pri_ip[0] and ip not in added_ips:
                     added_ips.append(ip)
         elif port_type == self.iso_net_id:
             ip_count += 1
             server_persona = ServerPersona(
                 server=self.server,
                 pnet=True,
                 snet=True,
                 inet=True,
                 pnet_fix_ipv4_count=ini_ips_count,
                 snet_fix_ipv4_count=ini_ips_count,
                 inet_fix_ipv4_count=ip_count,
                 network=self.network,
                 keypair=self.keypair,
                 ssh_username='******')
             # Get the added isolated IP address and saving the added
             # ips for removing
             isolated_ips = server_persona.inet_fix_ipv4
             for ip in isolated_ips:
                 if ip != self.initial_iso_ip[0] and ip not in added_ips:
                     added_ips.append(ip)
         self.assertServerPersonaFixedIps(server_persona)
     persona_args = {
         "server": self.server,
         "keypair": self.keypair,
         "pnet": True,
         "snet": True,
         "inet": True,
         "pnet_fix_ipv4_count": ini_ips_count,
         "snet_fix_ipv4_count": ini_ips_count,
         "inet_fix_ipv4_count": ini_ips_count,
         "network": self.network,
         "ssh_username": '******'
     }
     for ip_to_remove in added_ips:
         # Remove the added IP and assert the updated counts for IPv4
         removed_ip_response = self.servers_client.remove_fixed_ip(
             self.server.id, ip_to_remove)
         self.assertEqual(removed_ip_response.status_code,
                          NeutronResponseCodes.REMOVE_FIXED_IP,
                          msg=self.rem_msg.format(port_type, self.server.id,
                                                  removed_ip_response))
         if port_type == self.pub_net_id:
             ip_count -= 1
             persona_args["pnet_fix_ipv4_count"] = ip_count
         elif port_type == self.pri_net_id:
             ip_count -= 1
             persona_args["snet_fix_ipv4_count"] = ip_count
         elif port_type == self.iso_net_id:
             ip_count -= 1
             persona_args["inet_fix_ipv4_count"] = ip_count
         server_persona = ServerPersona(**persona_args)
         self.assertServerPersonaFixedIps(server_persona)