Пример #1
0
    def test_interface_attach_detach(self):
        min_kbps = 1000
        min_kpps = 100
        policy = self._create_qos_policy_with_bw_and_pps_rules(
            min_kbps, min_kpps)

        port = self._create_port_with_qos_policy(policy=None)

        port2 = self._create_port_with_qos_policy(policy=policy)

        server = self.create_server(networks=[{
            'port': port['id']
        }],
                                    wait_until='ACTIVE')

        self.assert_allocations(server, port, 0, 0)

        self.interface_client.create_interface(server_id=server['id'],
                                               port_id=port2['id'])
        waiters.wait_for_interface_status(self.interface_client, server['id'],
                                          port2['id'], 'ACTIVE')

        self.assert_allocations(server, port2, min_kbps, min_kpps)

        req_id = self.interface_client.delete_interface(
            server_id=server['id'],
            port_id=port2['id']).response['x-openstack-request-id']
        waiters.wait_for_interface_detach(self.servers_client, server['id'],
                                          port2['id'], req_id)

        self.assert_allocations(server, port2, 0, 0)
Пример #2
0
    def test_floatingip_port_details(self):
        """Tests the following:

        1. Create a port with floating ip in Neutron.
        2. Create two servers in Nova.
        3. Attach the port to the server.
        4. Detach the port from the server.
        5. Attach the port to the second server.
        6. Detach the port from the second server.
        """
        port = self.create_port(self.network)
        fip = self.create_and_associate_floatingip(port['id'])
        server1 = self._create_server(create_floating_ip=False)
        server2 = self._create_server(create_floating_ip=False)

        for server in [server1, server2]:
            # attach the port to the server
            self.create_interface(
                server['server']['id'], port_id=port['id'])
            waiters.wait_for_interface_status(
                self.os_primary.interfaces_client, server['server']['id'],
                port['id'], lib_constants.PORT_STATUS_ACTIVE)
            fip = self.client.show_floatingip(fip['id'])['floatingip']
            self._check_port_details(
                fip, port, status=lib_constants.PORT_STATUS_ACTIVE,
                device_id=server['server']['id'], device_owner='compute:nova')

            # detach the port from the server; this is a cast in the compute
            # API so we have to poll the port until the device_id is unset.
            self.delete_interface(server['server']['id'], port['id'])
            port = self._wait_for_port_detach(port['id'])
            fip = self._wait_for_fip_port_down(fip['id'])
            self._check_port_details(
                fip, port, status=lib_constants.PORT_STATUS_DOWN,
                device_id='', device_owner='')
 def _attach_interface_to_server(self):
     interface = self.interfaces_client.create_interface(
         self.server['id'])['interfaceAttachment']
     waiters.wait_for_interface_status(self.interfaces_client,
                                       self.server['id'],
                                       interface['port_id'], 'ACTIVE')
     self.addCleanup(test_utils.call_and_ignore_notfound_exc,
                     self.interfaces_client.delete_interface,
                     self.server['id'], interface['port_id'])
     return interface
Пример #4
0
 def test_wait_for_interface_status(self):
     self.client.show_interface.side_effect = [
         self._port_down(), self._port_active()
     ]
     with mock.patch.object(time, 'sleep') as sleep_mock:
         start_time = int(time.time())
         waiters.wait_for_interface_status(self.client, 'server_id',
                                           'port_id', 'ACTIVE')
         end_time = int(time.time())
         self.assertLess(end_time, (start_time + self.client.build_timeout))
         sleep_mock.assert_called_once_with(self.client.build_interval)
 def _attach_interface_to_server(self):
     network_id = self.network['id']
     interface = self.interfaces_client.create_interface(
         self.server['id'], net_id=network_id)['interfaceAttachment']
     self.addCleanup(
         test_utils.call_and_ignore_notfound_exc,
         self._delete_and_wait_for_interface_detach_ignore_timeout,
         self.server['id'], interface['port_id'])
     waiters.wait_for_interface_status(self.interfaces_client,
                                       self.server['id'],
                                       interface['port_id'], 'ACTIVE')
     return interface
 def test_create_interface(self):
     """Test create interface, part of os-attach-interfaces."""
     network_id = self.network['id']
     with self.override_role():
         interface = self.interfaces_client.create_interface(
             self.server['id'], net_id=network_id)['interfaceAttachment']
     self.addCleanup(
         test_utils.call_and_ignore_notfound_exc,
         self._delete_and_wait_for_interface_detach_ignore_timeout,
         self.server['id'], interface['port_id'])
     waiters.wait_for_interface_status(self.interfaces_client,
                                       self.server['id'],
                                       interface['port_id'], 'ACTIVE')
Пример #7
0
 def _test_create_interface(self, server):
     iface = (self.interfaces_client.create_interface(
         server['id'])['interfaceAttachment'])
     iface = waiters.wait_for_interface_status(self.interfaces_client,
                                               server['id'],
                                               iface['port_id'], 'ACTIVE')
     return iface
 def _test_create_interface(self, server):
     iface = (self.interfaces_client.create_interface(server['id'])
              ['interfaceAttachment'])
     iface = waiters.wait_for_interface_status(
         self.interfaces_client, server['id'], iface['port_id'], 'ACTIVE')
     self._check_interface(iface)
     return iface
Пример #9
0
 def _create_server_get_interfaces(self):
     validation_resources = self.get_test_validation_resources(
         self.os_primary)
     server = self.create_test_server(
         validatable=True,
         validation_resources=validation_resources,
         wait_until='ACTIVE')
     # NOTE(mgoddard): Get detailed server to ensure addresses are present
     # in fixed IP case.
     server = self.servers_client.show_server(server['id'])['server']
     # NOTE(artom) self.create_test_server adds cleanups, but this is
     # apparently not enough? Add cleanup here.
     self.addCleanup(self.delete_server, server['id'])
     self._wait_for_validation(server, validation_resources)
     try:
         fip = set([validation_resources['floating_ip']['ip']])
     except KeyError:
         fip = ()
     ifs = (self.interfaces_client.list_interfaces(
         server['id'])['interfaceAttachments'])
     body = waiters.wait_for_interface_status(self.interfaces_client,
                                              server['id'],
                                              ifs[0]['port_id'], 'ACTIVE')
     ifs[0]['port_state'] = body['port_state']
     return server, ifs, fip
 def _test_create_interface_by_network_id(self, server, ifs):
     network_id = ifs[0]['net_id']
     iface = self.interfaces_client.create_interface(
         server['id'], net_id=network_id)['interfaceAttachment']
     iface = waiters.wait_for_interface_status(
         self.interfaces_client, server['id'], iface['port_id'], 'ACTIVE')
     self._check_interface(iface, network_id=network_id)
     return iface
Пример #11
0
 def _create_server_get_interfaces(self):
     server = self.create_test_server(wait_until='ACTIVE')
     ifs = (self.interfaces_client.list_interfaces(server['id'])
            ['interfaceAttachments'])
     body = waiters.wait_for_interface_status(
         self.interfaces_client, server['id'], ifs[0]['port_id'], 'ACTIVE')
     ifs[0]['port_state'] = body['port_state']
     return server, ifs
Пример #12
0
 def _test_create_interface_by_network_id(self, server, ifs):
     network_id = ifs[0]['net_id']
     iface = self.interfaces_client.create_interface(
         server['id'], net_id=network_id)['interfaceAttachment']
     iface = waiters.wait_for_interface_status(
         self.interfaces_client, server['id'], iface['port_id'], 'ACTIVE')
     self._check_interface(iface, network_id=network_id)
     return iface
Пример #13
0
 def _create_server_get_interfaces(self):
     server = self.create_test_server(wait_until='ACTIVE')
     ifs = (self.interfaces_client.list_interfaces(server['id'])
            ['interfaceAttachments'])
     body = waiters.wait_for_interface_status(
         self.interfaces_client, server['id'], ifs[0]['port_id'], 'ACTIVE')
     ifs[0]['port_state'] = body['port_state']
     return server, ifs
Пример #14
0
 def _test_create_interface_by_port_id(self, server, ifs):
     network_id = ifs[0]['net_id']
     port = self.ports_client.create_port(network_id=network_id)
     port_id = port['port']['id']
     self.addCleanup(self.ports_client.delete_port, port_id)
     iface = self.interfaces_client.create_interface(
         server['id'], port_id=port_id)['interfaceAttachment']
     iface = waiters.wait_for_interface_status(
         self.interfaces_client, server['id'], iface['port_id'], 'ACTIVE')
     self._check_interface(iface, port_id=port_id)
     return iface
 def _test_create_interface_by_port_id(self, server, ifs):
     network_id = ifs[0]['net_id']
     port = self.ports_client.create_port(network_id=network_id)
     port_id = port['port']['id']
     self.addCleanup(self.ports_client.delete_port, port_id)
     iface = self.interfaces_client.create_interface(
         server['id'], port_id=port_id)['interfaceAttachment']
     iface = waiters.wait_for_interface_status(
         self.interfaces_client, server['id'], iface['port_id'], 'ACTIVE')
     self._check_interface(iface, port_id=port_id)
     return iface
Пример #16
0
 def _check_interface(self, iface, server_id=None, port_id=None,
                      network_id=None, fixed_ip=None, mac_addr=None):
     if server_id:
         iface = waiters.wait_for_interface_status(
             self.interfaces_client, server_id, iface['port_id'], 'ACTIVE')
     if port_id:
         self.assertEqual(iface['port_id'], port_id)
     if network_id:
         self.assertEqual(iface['net_id'], network_id)
     if fixed_ip:
         self.assertEqual(iface['fixed_ips'][0]['ip_address'], fixed_ip)
     if mac_addr:
         self.assertEqual(iface['mac_addr'], mac_addr)
Пример #17
0
 def _check_interface(self, iface, server_id=None, port_id=None,
                      network_id=None, fixed_ip=None, mac_addr=None):
     if server_id:
         iface = waiters.wait_for_interface_status(
             self.interfaces_client, server_id, iface['port_id'], 'ACTIVE')
     if port_id:
         self.assertEqual(iface['port_id'], port_id)
     if network_id:
         self.assertEqual(iface['net_id'], network_id)
     if fixed_ip:
         self.assertEqual(iface['fixed_ips'][0]['ip_address'], fixed_ip)
     if mac_addr:
         self.assertEqual(iface['mac_addr'], mac_addr)
Пример #18
0
    def test_wait_for_interface_status(self):
        show_interface = mock.Mock(
            side_effect=[self.port_down, self.port_active])
        client = self.mock_client(show_interface=show_interface)
        self.patch('time.time', return_value=0.)
        sleep = self.patch('time.sleep')

        result = waiters.wait_for_interface_status(
            client, 'server_id', 'port_id', 'ACTIVE')

        self.assertIs(self.port_active['interfaceAttachment'], result)
        show_interface.assert_has_calls([mock.call('server_id', 'port_id'),
                                         mock.call('server_id', 'port_id')])
        sleep.assert_called_once_with(client.build_interval)
Пример #19
0
    def _test_create_interface_by_fixed_ips(self, server, ifs):
        network_id = ifs[0]['net_id']
        subnet_id = ifs[0]['fixed_ips'][0]['subnet_id']
        ip_list = net_utils.get_unused_ip_addresses(self.ports_client,
                                                    self.subnets_client,
                                                    network_id, subnet_id, 1)

        fixed_ips = [{'ip_address': ip_list[0]}]
        iface = self.interfaces_client.create_interface(
            server['id'], net_id=network_id,
            fixed_ips=fixed_ips)['interfaceAttachment']
        self.addCleanup(self.ports_client.delete_port, iface['port_id'])
        iface = waiters.wait_for_interface_status(self.interfaces_client,
                                                  server['id'],
                                                  iface['port_id'], 'ACTIVE')
        self._check_interface(iface, fixed_ip=ip_list[0])
        return iface
Пример #20
0
 def _create_server_get_interfaces(self):
     validation_resources = self.get_test_validation_resources(
         self.os_primary)
     server = self.create_test_server(
         validatable=True,
         validation_resources=validation_resources,
         wait_until='ACTIVE')
     # NOTE(artom) self.create_test_server adds cleanups, but this is
     # apparently not enough? Add cleanup here.
     self.addCleanup(self.delete_server, server['id'])
     self._wait_for_validation(server, validation_resources)
     ifs = (self.interfaces_client.list_interfaces(server['id'])
            ['interfaceAttachments'])
     body = waiters.wait_for_interface_status(
         self.interfaces_client, server['id'], ifs[0]['port_id'], 'ACTIVE')
     ifs[0]['port_state'] = body['port_state']
     return server, ifs
Пример #21
0
 def _create_server_get_interfaces(self):
     validation_resources = self.get_test_validation_resources(
         self.os_primary)
     server = self.create_test_server(
         validatable=True,
         validation_resources=validation_resources,
         wait_until='ACTIVE')
     # NOTE(artom) self.create_test_server adds cleanups, but this is
     # apparently not enough? Add cleanup here.
     self.addCleanup(self.delete_server, server['id'])
     self._wait_for_validation(server, validation_resources)
     ifs = (self.interfaces_client.list_interfaces(server['id'])
            ['interfaceAttachments'])
     body = waiters.wait_for_interface_status(
         self.interfaces_client, server['id'], ifs[0]['port_id'], 'ACTIVE')
     ifs[0]['port_state'] = body['port_state']
     return server, ifs
    def _test_create_interface_by_fixed_ips(self, server, ifs):
        network_id = ifs[0]['net_id']
        subnet_id = ifs[0]['fixed_ips'][0]['subnet_id']
        ip_list = net_utils.get_unused_ip_addresses(self.ports_client,
                                                    self.subnets_client,
                                                    network_id,
                                                    subnet_id,
                                                    1)

        fixed_ips = [{'ip_address': ip_list[0]}]
        iface = self.interfaces_client.create_interface(
            server['id'], net_id=network_id,
            fixed_ips=fixed_ips)['interfaceAttachment']
        self.addCleanup(self.ports_client.delete_port, iface['port_id'])
        iface = waiters.wait_for_interface_status(
            self.interfaces_client, server['id'], iface['port_id'], 'ACTIVE')
        self._check_interface(iface, fixed_ip=ip_list[0])
        return iface
Пример #23
0
def wait_for_interface_status(client, server_id, port_id, status,
                              ssh_client=None, mac_address=None):
    """Waits for an interface to reach a given status and checks VM NIC

    This method enhances the tempest one. Apart from checking the interface
    status returned by Nova, this methods access the VM to check if the NIC
    interface is already detected by the kernel.
    """
    body = waiters.wait_for_interface_status(client, server_id, port_id,
                                             status)

    if ssh_client and mac_address:
        ip_command = IPCommand(ssh_client)
        common_utils.wait_until_true(
            lambda: ip_command.get_nic_name_by_mac(mac_address),
            timeout=10,
            exception=RuntimeError('Interface with MAC %s not present in the '
                                   'VM' % mac_address))

    return body
Пример #24
0
    def test_create_get_list_interfaces(self):
        """Test interface API with microversion greater than 2.69

        Checking create, get, list interface APIs response schema.
        """
        server = self.create_test_server(wait_until='ACTIVE')
        try:
            iface = self.interfaces_client.create_interface(
                server['id'])['interfaceAttachment']
            iface = waiters.wait_for_interface_status(self.interfaces_client,
                                                      server['id'],
                                                      iface['port_id'],
                                                      'ACTIVE')
        except lib_exc.BadRequest as e:
            msg = ('Multiple possible networks found, use a Network ID to be '
                   'more specific.')
            if not CONF.compute.fixed_network_name and str(e) == msg:
                raise
        else:
            # just to check the response schema
            self.interfaces_client.show_interface(server['id'],
                                                  iface['port_id'])
            self.interfaces_client.list_interfaces(server['id'])