Exemplo n.º 1
0
    def test_detach_ip_from_server(self):
        self._setup_networks()

        new_server = self.user_cloud.create_server(wait=True,
                                                   name=self.new_item_name +
                                                   '_server',
                                                   image=self.image,
                                                   flavor=self.flavor,
                                                   nics=[self.nic])

        # ToDo: remove the following iteration when create_server waits for
        # the IP to be attached
        ip = None
        for _ in _utils._iterate_timeout(
                self.timeout, "Timeout waiting for IP address to be attached"):
            ip = meta.get_server_external_ipv4(self.user_cloud, new_server)
            if ip is not None:
                break
            new_server = self.user_cloud.get_server(new_server.id)

        self.addCleanup(self._cleanup_ips, new_server)

        f_ip = self.user_cloud.get_floating_ip(
            id=None, filters={'floating_ip_address': ip})
        self.user_cloud.detach_ip_from_server(server_id=new_server.id,
                                              floating_ip_id=f_ip['id'])
Exemplo n.º 2
0
 def test_iterate_timeout_bad_wait(self):
     with testtools.ExpectedException(
             exc.OpenStackCloudException,
             "Wait value must be an int or float value."):
         for count in _utils._iterate_timeout(
                 1, "test_iterate_timeout_bad_wait", wait="timeishard"):
             pass
Exemplo n.º 3
0
 def test_iterate_timeout_int_wait(self, mock_sleep):
     iter = _utils._iterate_timeout(10,
                                    "test_iterate_timeout_int_wait",
                                    wait=1)
     next(iter)
     next(iter)
     mock_sleep.assert_called_with(1.0)
Exemplo n.º 4
0
 def test_iterate_timeout_bad_wait(self):
     with testtools.ExpectedException(
             exc.OpenStackCloudException,
             "Wait value must be an int or float value."):
         for count in _utils._iterate_timeout(
                 1, "test_iterate_timeout_bad_wait", wait="timeishard"):
             pass
Exemplo n.º 5
0
 def cleanup(self, volume, snapshot_name=None, image_name=None):
     # Need to delete snapshots before volumes
     if snapshot_name:
         snapshot = self.user_cloud.get_volume_snapshot(snapshot_name)
         if snapshot:
             self.user_cloud.delete_volume_snapshot(snapshot_name,
                                                    wait=True)
     if image_name:
         image = self.user_cloud.get_image(image_name)
         if image:
             self.user_cloud.delete_image(image_name, wait=True)
     if not isinstance(volume, list):
         self.user_cloud.delete_volume(volume, wait=True)
     else:
         # We have more than one volume to clean up - submit all of the
         # deletes without wait, then poll until none of them are found
         # in the volume list anymore
         for v in volume:
             self.user_cloud.delete_volume(v, wait=False)
         for count in _utils._iterate_timeout(
                 180, "Timeout waiting for volume cleanup"):
             found = False
             for existing in self.user_cloud.list_volumes():
                 for v in volume:
                     if v['id'] == existing['id']:
                         found = True
                         break
                 if found:
                     break
             if not found:
                 break
Exemplo n.º 6
0
 def cleanup(self, volume, snapshot_name=None, image_name=None):
     # Need to delete snapshots before volumes
     if snapshot_name:
         snapshot = self.user_cloud.get_volume_snapshot(snapshot_name)
         if snapshot:
             self.user_cloud.delete_volume_snapshot(
                 snapshot_name, wait=True)
     if image_name:
         image = self.user_cloud.get_image(image_name)
         if image:
             self.user_cloud.delete_image(image_name, wait=True)
     if not isinstance(volume, list):
         self.user_cloud.delete_volume(volume, wait=True)
     else:
         # We have more than one volume to clean up - submit all of the
         # deletes without wait, then poll until none of them are found
         # in the volume list anymore
         for v in volume:
             self.user_cloud.delete_volume(v, wait=False)
         for count in _utils._iterate_timeout(
                 180, "Timeout waiting for volume cleanup"):
             found = False
             for existing in self.user_cloud.list_volumes():
                 for v in volume:
                     if v['id'] == existing['id']:
                         found = True
                         break
                 if found:
                     break
             if not found:
                 break
Exemplo n.º 7
0
 def test_iterate_timeout_timeout(self, mock_sleep):
     message = "timeout test"
     with testtools.ExpectedException(
             exc.OpenStackCloudTimeout,
             message):
         for count in _utils._iterate_timeout(0.1, message, wait=1):
             pass
     mock_sleep.assert_called_with(1.0)
Exemplo n.º 8
0
 def test_iterate_timeout_timeout(self, mock_sleep):
     message = "timeout test"
     with testtools.ExpectedException(
             exc.OpenStackCloudTimeout,
             message):
         for count in _utils._iterate_timeout(0.1, message, wait=1):
             pass
     mock_sleep.assert_called_with(1.0)
Exemplo n.º 9
0
 def _wait_for_detach(self, volume_id):
     # Volumes do not show up as unattached for a bit immediately after
     # deleting a server that had had a volume attached. Yay for eventual
     # consistency!
     for count in _utils._iterate_timeout(
             60, 'Timeout waiting for volume {volume_id} to detach'.format(
                 volume_id=volume_id)):
         volume = self.user_cloud.get_volume(volume_id)
         if volume.status in ('available', 'error', 'error_restoring',
                              'error_extending'):
             return
Exemplo n.º 10
0
 def test_get_server_console_name_or_id(self):
     self.addCleanup(self._cleanup_servers_and_volumes, self.server_name)
     self.user_cloud.create_server(name=self.server_name,
                                   image=self.image,
                                   flavor=self.flavor,
                                   wait=True)
     for _ in _utils._iterate_timeout(
             5, "Did not get more than 0 lines in the console log"):
         log = self.user_cloud.get_server_console(server=self.server_name)
         self.assertTrue(isinstance(log, six.string_types))
         if len(log) > 0:
             break
Exemplo n.º 11
0
 def _wait_for_detach(self, volume_id):
     # Volumes do not show up as unattached for a bit immediately after
     # deleting a server that had had a volume attached. Yay for eventual
     # consistency!
     for count in _utils._iterate_timeout(
             60,
             'Timeout waiting for volume {volume_id} to detach'.format(
                 volume_id=volume_id)):
         volume = self.user_cloud.get_volume(volume_id)
         if volume.status in (
                 'available', 'error',
                 'error_restoring', 'error_extending'):
             return
Exemplo n.º 12
0
 def test_get_server_console_name_or_id(self):
     self.addCleanup(self._cleanup_servers_and_volumes, self.server_name)
     self.user_cloud.create_server(
         name=self.server_name,
         image=self.image,
         flavor=self.flavor,
         wait=True)
     for _ in _utils._iterate_timeout(
             5, "Did not get more than 0 lines in the console log"):
         log = self.user_cloud.get_server_console(server=self.server_name)
         self.assertTrue(isinstance(log, six.string_types))
         if len(log) > 0:
             break
Exemplo n.º 13
0
    def test_add_auto_ip(self):
        self._setup_networks()

        new_server = self.cloud.create_server(
            wait=True, name=self.new_item_name + '_server',
            image=self.image,
            flavor=self.flavor, nics=[self.nic])

        # ToDo: remove the following iteration when create_server waits for
        # the IP to be attached
        ip = None
        for _ in _utils._iterate_timeout(
                self.timeout, "Timeout waiting for IP address to be attached"):
            ip = meta.get_server_external_ipv4(self.cloud, new_server)
            if ip is not None:
                break
            new_server = self.cloud.get_server(new_server.id)

        self.addCleanup(self._cleanup_ips, new_server)
Exemplo n.º 14
0
 def cleanup(self, volume, snapshot_name=None, image_name=None):
     # Need to delete snapshots before volumes
     if snapshot_name:
         snapshot = self.user_cloud.get_volume_snapshot(snapshot_name)
         if snapshot:
             self.user_cloud.delete_volume_snapshot(snapshot_name,
                                                    wait=True)
     if image_name:
         image = self.user_cloud.get_image(image_name)
         if image:
             self.user_cloud.delete_image(image_name, wait=True)
     if not isinstance(volume, list):
         self.user_cloud.delete_volume(volume, wait=True)
     else:
         # We have more than one volume to clean up - submit all of the
         # deletes without wait, then poll until none of them are found
         # in the volume list anymore
         for v in volume:
             self.user_cloud.delete_volume(v, wait=False)
         try:
             for count in _utils._iterate_timeout(
                     180, "Timeout waiting for volume cleanup"):
                 found = False
                 for existing in self.user_cloud.list_volumes():
                     for v in volume:
                         if v['id'] == existing['id']:
                             found = True
                             break
                     if found:
                         break
                 if not found:
                     break
         except (exc.OpenStackCloudTimeout, TimeoutException):
             # NOTE(slaweq): ups, some volumes are still not removed
             # so we should try to force delete it once again and move
             # forward
             for existing in self.user_cloud.list_volumes():
                 for v in volume:
                     if v['id'] == existing['id']:
                         self.operator_cloud.delete_volume(v,
                                                           wait=False,
                                                           force=True)
Exemplo n.º 15
0
    def _cleanup_servers(self):
        exception_list = list()

        # Delete stale servers as well as server created for this test
        for i in self.nova.servers.list():
            if i.name.startswith(self.new_item_name):
                self.nova.servers.delete(i)
                for _ in _utils._iterate_timeout(self.timeout,
                                                 "Timeout deleting servers"):
                    try:
                        self.nova.servers.get(server=i)
                    except nova_exc.NotFound:
                        break
                    except Exception as e:
                        exception_list.append(str(e))
                        continue

        if exception_list:
            # Raise an error: we must make users aware that something went
            # wrong
            raise OpenStackCloudException('\n'.join(exception_list))
Exemplo n.º 16
0
    def _cleanup_servers(self):
        exception_list = list()

        # Delete stale servers as well as server created for this test
        for i in self.nova.servers.list():
            if i.name.startswith(self.new_item_name):
                self.nova.servers.delete(i)
                for _ in _utils._iterate_timeout(
                        self.timeout, "Timeout deleting servers"):
                    try:
                        self.nova.servers.get(server=i)
                    except nova_exc.NotFound:
                        break
                    except Exception as e:
                        exception_list.append(str(e))
                        continue

        if exception_list:
            # Raise an error: we must make users aware that something went
            # wrong
            raise OpenStackCloudException('\n'.join(exception_list))
Exemplo n.º 17
0
 def test_iterate_timeout_int_wait(self, mock_sleep):
     iter = _utils._iterate_timeout(
         10, "test_iterate_timeout_int_wait", wait=1)
     next(iter)
     next(iter)
     mock_sleep.assert_called_with(1.0)