예제 #1
0
    def setUp(self):
        super(TestFloatingIP, self).setUp()
        self.floating_ips = [
            fakes.FakeFloatingIP(**ip) for ip in self.mock_floating_ip_list_rep
        ]

        self.fake_server = meta.obj_to_dict(
            fakes.FakeServer('server-id',
                             '',
                             'ACTIVE',
                             addresses={
                                 u'test_pnztt_net': [{
                                     u'OS-EXT-IPS:type':
                                     u'fixed',
                                     u'addr':
                                     '192.0.2.129',
                                     u'version':
                                     4,
                                     u'OS-EXT-IPS-MAC:mac_addr':
                                     u'fa:16:3e:ae:7d:42'
                                 }]
                             }))

        self.floating_ip = _utils.normalize_nova_floating_ips(
            meta.obj_list_to_dict(self.floating_ips))[0]
예제 #2
0
 def test_rebuild_server_wait(self, mock_nova):
     """
     Test that rebuild_server with a wait returns the server instance when
     its status changes to "ACTIVE".
     """
     rebuild_server = fakes.FakeServer('1234', '', 'REBUILD')
     active_server = fakes.FakeServer('1234', '', 'ACTIVE')
     fake_floating_ip = fakes.FakeFloatingIP('1234', 'ippool',
                                             '1.1.1.1', '2.2.2.2',
                                             '5678')
     mock_nova.servers.rebuild.return_value = rebuild_server
     mock_nova.servers.list.return_value = [active_server]
     self.register_uris([
         dict(method='GET',
              uri=self.get_mock_url(
                  'network', 'public', append=['v2.0', 'ports.json'],
                  qs_elements=['device_id=1234']),
              json={'ports': []}),
         dict(method='GET',
              uri=self.get_mock_url(
                  'network', 'public', append=['v2.0', 'networks.json']),
              json={'networks': []}),
         dict(method='GET',
              uri=self.get_mock_url(
                  'network', 'public', append=['v2.0', 'floatingips.json']),
              json={'floatingips': [fake_floating_ip]})
     ])
     self.cloud.name = 'cloud-name'
     self.assertEqual(
         self.cloud._normalize_server(
             meta.obj_to_munch(active_server)),
         self.cloud.rebuild_server("1234", "b", wait=True))
     # TODO(slaweq): change do_count to True when all nova mocks will be
     # replaced with request_mocks also
     self.assert_calls(do_count=False)
예제 #3
0
 def test_rebuild_server_with_admin_pass_wait(self):
     """
     Test that a server with an admin_pass passed returns the password
     """
     with patch("shade.OpenStackCloud"):
         rebuild_server = fakes.FakeServer('1234',
                                           '',
                                           'REBUILD',
                                           adminPass='******')
         active_server = fakes.FakeServer('1234', '', 'ACTIVE')
         ret_active_server = fakes.FakeServer('1234',
                                              '',
                                              'ACTIVE',
                                              adminPass='******')
         fake_floating_ip = fakes.FakeFloatingIP('1234', 'ippool',
                                                 '1.1.1.1', '2.2.2.2',
                                                 '5678')
         config = {
             "servers.rebuild.return_value": rebuild_server,
             "servers.list.return_value": [active_server],
             "floating_ips.list.return_value": [fake_floating_ip]
         }
         OpenStackCloud.nova_client = Mock(**config)
         self.cloud.name = 'cloud-name'
         self.assertEqual(
             _utils.normalize_server(meta.obj_to_dict(ret_active_server),
                                     cloud_name='cloud-name',
                                     region_name='RegionOne'),
             self.cloud.rebuild_server("1234",
                                       "b",
                                       wait=True,
                                       admin_pass='******'))
예제 #4
0
 def test_create_server_no_addresses(self, mock_sleep):
     """
     Test that create_server with a wait throws an exception if the
     server doesn't have addresses.
     """
     with patch("shade.OpenStackCloud.nova_client"):
         build_server = fakes.FakeServer('1234', '', 'BUILD')
         fake_server = fakes.FakeServer('1234', '', 'ACTIVE')
         fake_floating_ip = fakes.FakeFloatingIP('1234', 'ippool',
                                                 '1.1.1.1', '2.2.2.2',
                                                 '5678')
         config = {
             "servers.create.return_value": build_server,
             "servers.get.return_value": [build_server, None],
             "servers.list.side_effect": [[build_server], [fake_server]],
             "servers.delete.return_value": None,
             "floating_ips.list.return_value": [fake_floating_ip]
         }
         OpenStackCloud.nova_client = Mock(**config)
         self.cloud._SERVER_AGE = 0
         with patch.object(OpenStackCloud,
                           "add_ips_to_server",
                           return_value=fake_server):
             self.assertRaises(OpenStackCloudException,
                               self.cloud.create_server,
                               'server-name',
                               'image-id',
                               'flavor-id',
                               wait=True)
예제 #5
0
 def test_rebuild_server_server_error(self, mock_nova):
     """
     Test that a server error while waiting for the server to rebuild
     raises an exception in rebuild_server.
     """
     rebuild_server = fakes.FakeServer('1234', '', 'REBUILD')
     error_server = fakes.FakeServer('1234', '', 'ERROR')
     fake_floating_ip = fakes.FakeFloatingIP('1234', 'ippool', '1.1.1.1',
                                             '2.2.2.2', '5678')
     mock_nova.servers.rebuild.return_value = rebuild_server
     mock_nova.servers.list.return_value = [error_server]
     self.register_uris([
         dict(method='GET',
              uri=self.get_mock_url('network',
                                    'public',
                                    append=['v2.0', 'ports.json'],
                                    qs_elements=['device_id=1234']),
              json={'ports': []}),
         dict(method='GET',
              uri=self.get_mock_url('network',
                                    'public',
                                    append=['v2.0', 'floatingips.json']),
              json={'floatingips': [fake_floating_ip]})
     ])
     self.assertRaises(exc.OpenStackCloudException,
                       self.cloud.rebuild_server,
                       "1234",
                       "b",
                       wait=True)
     # TODO(slaweq): change do_count to True when all nova mocks will be
     # replaced with request_mocks also
     self.assert_calls(do_count=False)
예제 #6
0
 def test_create_server_with_admin_pass_no_wait(self):
     """
     Test that a server with an admin_pass passed returns the password
     """
     with patch("shade.OpenStackCloud.nova_client"):
         fake_server = fakes.FakeServer('1234', '', 'BUILD')
         fake_create_server = fakes.FakeServer('1234',
                                               '',
                                               'BUILD',
                                               adminPass='******')
         fake_floating_ip = fakes.FakeFloatingIP('1234', 'ippool',
                                                 '1.1.1.1', '2.2.2.2',
                                                 '5678')
         config = {
             "servers.create.return_value": fake_create_server,
             "servers.get.return_value": fake_server,
             "floating_ips.list.return_value": [fake_floating_ip]
         }
         OpenStackCloud.nova_client = Mock(**config)
         self.assertEqual(
             _utils.normalize_server(meta.obj_to_dict(fake_create_server),
                                     cloud_name=self.cloud.name,
                                     region_name=self.cloud.region_name),
             self.cloud.create_server(name='server-name',
                                      image=dict(id='image=id'),
                                      flavor=dict(id='flavor-id'),
                                      admin_pass='******'))
예제 #7
0
    def test_create_floating_ip(self, mock_has_service, mock_nova_client):
        mock_has_service.side_effect = has_service_side_effect
        mock_nova_client.floating_ips.create.return_value =\
            fakes.FakeFloatingIP(**self.mock_floating_ip_list_rep[1])

        self.cloud.create_floating_ip(network='nova')

        mock_nova_client.floating_ips.create.assert_called_with(pool='nova')
예제 #8
0
    def test_detach_ip_from_server(self, mock_has_service, mock_nova_client):
        mock_has_service.side_effect = has_service_side_effect
        mock_nova_client.floating_ips.list.return_value = [
            fakes.FakeFloatingIP(**ip) for ip in self.mock_floating_ip_list_rep
        ]

        self.cloud.detach_ip_from_server(server_id='server-id',
                                         floating_ip_id=1)

        mock_nova_client.servers.remove_floating_ip.assert_called_with(
            server='server-id', address='203.0.113.1')
예제 #9
0
    def test_available_floating_ip_new(self, mock_has_service,
                                       mock__nova_list_floating_ips,
                                       mock_nova_client):
        mock_has_service.side_effect = has_service_side_effect
        mock__nova_list_floating_ips.return_value = []
        mock_nova_client.floating_ips.create.return_value = \
            fakes.FakeFloatingIP(**self.mock_floating_ip_list_rep[0])

        ip = self.cloud.available_floating_ip(network='nova')

        self.assertEqual(self.mock_floating_ip_list_rep[0]['ip'],
                         ip['floating_ip_address'])
예제 #10
0
 def test_update_server_name(self, mock_nova):
     """
     Test that update_server updates the name without raising any exception
     """
     fake_server = fakes.FakeServer('1234', 'server-name', 'ACTIVE')
     fake_update_server = fakes.FakeServer('1234', 'server-name2', 'ACTIVE')
     fake_floating_ip = fakes.FakeFloatingIP('1234', 'ippool', '1.1.1.1',
                                             '2.2.2.2', '5678')
     mock_nova.servers.list.return_value = [fake_server]
     mock_nova.servers.update.return_value = fake_update_server
     mock_nova.floating_ips.list.return_value = [fake_floating_ip]
     self.assertEqual(
         'server-name2',
         self.cloud.update_server('server-name',
                                  name='server-name2')['name'])
예제 #11
0
 def test_rebuild_server_server_error(self, mock_nova):
     """
     Test that a server error while waiting for the server to rebuild
     raises an exception in rebuild_server.
     """
     rebuild_server = fakes.FakeServer('1234', '', 'REBUILD')
     error_server = fakes.FakeServer('1234', '', 'ERROR')
     fake_floating_ip = fakes.FakeFloatingIP('1234', 'ippool',
                                             '1.1.1.1', '2.2.2.2',
                                             '5678')
     mock_nova.servers.rebuild.return_value = rebuild_server
     mock_nova.servers.list.return_value = [error_server]
     # TODO(slaweq): change this to neutron floating ips and turn neutron
     # back on for this test when you get to floating ips
     mock_nova.floating_ips.list.return_value = [fake_floating_ip]
     self.assertRaises(
         exc.OpenStackCloudException,
         self.cloud.rebuild_server, "1234", "b", wait=True)
예제 #12
0
    def test_create_server_no_addresses(self, mock_sleep, mock_nova,
                                        mock_add_ips_to_server):
        """
        Test that create_server with a wait throws an exception if the
        server doesn't have addresses.
        """
        build_server = fakes.FakeServer('1234', '', 'BUILD')
        fake_server = fakes.FakeServer('1234', '', 'ACTIVE')
        fake_floating_ip = fakes.FakeFloatingIP('1234', 'ippool', '1.1.1.1',
                                                '2.2.2.2', '5678')
        mock_nova.servers.create.return_value = build_server
        mock_nova.servers.get.return_value = [build_server, None]
        mock_nova.servers.list.side_effect = [[build_server], [fake_server]]
        mock_nova.servers.delete.return_value = None
        self.register_uris([
            dict(method='GET',
                 uri=self.get_mock_url('network',
                                       'public',
                                       append=['v2.0', 'networks.json']),
                 json={'networks': []}),
            dict(method='GET',
                 uri=self.get_mock_url('network',
                                       'public',
                                       append=['v2.0', 'ports.json'],
                                       qs_elements=['device_id=1234']),
                 json={'ports': []}),
            dict(method='GET',
                 uri=self.get_mock_url('network',
                                       'public',
                                       append=['v2.0', 'floatingips.json']),
                 json={'floatingips': [fake_floating_ip]})
        ])
        mock_add_ips_to_server.return_value = fake_server
        self.cloud._SERVER_AGE = 0

        self.assertRaises(exc.OpenStackCloudException,
                          self.cloud.create_server,
                          'server-name', {'id': 'image-id'},
                          {'id': 'flavor-id'},
                          wait=True)
        # TODO(slaweq): change do_count to True when all nova mocks will be
        # replaced with request_mocks also
        self.assert_calls(do_count=False)
예제 #13
0
 def test_rebuild_server_wait(self, mock_nova):
     """
     Test that rebuild_server with a wait returns the server instance when
     its status changes to "ACTIVE".
     """
     rebuild_server = fakes.FakeServer('1234', '', 'REBUILD')
     active_server = fakes.FakeServer('1234', '', 'ACTIVE')
     fake_floating_ip = fakes.FakeFloatingIP('1234', 'ippool',
                                             '1.1.1.1', '2.2.2.2',
                                             '5678')
     mock_nova.servers.rebuild.return_value = rebuild_server
     mock_nova.servers.list.return_value = [active_server]
     # TODO(slaweq): change this to neutron floating ips and turn neutron
     # back on for this test when you get to floating ips
     mock_nova.floating_ips.list.return_value = [fake_floating_ip]
     self.cloud.name = 'cloud-name'
     self.assertEqual(
         self.cloud._normalize_server(
             meta.obj_to_dict(active_server)),
         self.cloud.rebuild_server("1234", "b", wait=True))
예제 #14
0
 def test_create_server_with_admin_pass_no_wait(self, mock_nova):
     """
     Test that a server with an admin_pass passed returns the password
     """
     fake_server = fakes.FakeServer('1234', '', 'BUILD')
     fake_create_server = fakes.FakeServer('1234',
                                           '',
                                           'BUILD',
                                           adminPass='******')
     fake_floating_ip = fakes.FakeFloatingIP('1234', 'ippool', '1.1.1.1',
                                             '2.2.2.2', '5678')
     mock_nova.servers.create.return_value = fake_create_server
     mock_nova.servers.get.return_value = fake_server
     self.register_uris([
         dict(method='GET',
              uri=self.get_mock_url('network',
                                    'public',
                                    append=['v2.0', 'networks.json']),
              json={'networks': []}),
         dict(method='GET',
              uri=self.get_mock_url('network',
                                    'public',
                                    append=['v2.0', 'ports.json'],
                                    qs_elements=['device_id=1234']),
              json={'ports': []}),
         dict(method='GET',
              uri=self.get_mock_url('network',
                                    'public',
                                    append=['v2.0', 'floatingips.json']),
              json={'floatingips': [fake_floating_ip]})
     ])
     self.assertEqual(
         self.cloud._normalize_server(
             meta.obj_to_munch(fake_create_server)),
         self.cloud.create_server(name='server-name',
                                  image=dict(id='image=id'),
                                  flavor=dict(id='flavor-id'),
                                  admin_pass='******'))
     # TODO(slaweq): change do_count to True when all nova mocks will be
     # replaced with request_mocks also
     self.assert_calls(do_count=False)
예제 #15
0
 def test_rebuild_server_server_error(self):
     """
     Test that a server error while waiting for the server to rebuild
     raises an exception in rebuild_server.
     """
     rebuild_server = fakes.FakeServer('1234', '', 'REBUILD')
     error_server = fakes.FakeServer('1234', '', 'ERROR')
     fake_floating_ip = fakes.FakeFloatingIP('1234', 'ippool', '1.1.1.1',
                                             '2.2.2.2', '5678')
     with patch("shade.OpenStackCloud"):
         config = {
             "servers.rebuild.return_value": rebuild_server,
             "servers.list.return_value": [error_server],
             "floating_ips.list.return_value": [fake_floating_ip]
         }
         OpenStackCloud.nova_client = Mock(**config)
         self.assertRaises(OpenStackCloudException,
                           self.cloud.rebuild_server,
                           "1234",
                           "b",
                           wait=True)
예제 #16
0
 def test_update_server_name(self):
     """
     Test that update_server updates the name without raising any exception
     """
     with patch("shade.OpenStackCloud"):
         fake_server = fakes.FakeServer('1234', 'server-name', 'ACTIVE')
         fake_update_server = fakes.FakeServer('1234', 'server-name2',
                                               'ACTIVE')
         fake_floating_ip = fakes.FakeFloatingIP('1234', 'ippool',
                                                 '1.1.1.1', '2.2.2.2',
                                                 '5678')
         config = {
             "servers.list.return_value": [fake_server],
             "servers.update.return_value": fake_update_server,
             "floating_ips.list.return_value": [fake_floating_ip]
         }
         OpenStackCloud.nova_client = Mock(**config)
         self.assertEqual(
             'server-name2',
             self.cloud.update_server(
                 'server-name', name='server-name2')['name'])
예제 #17
0
 def test_rebuild_server_wait(self):
     """
     Test that rebuild_server with a wait returns the server instance when
     its status changes to "ACTIVE".
     """
     with patch("shade.OpenStackCloud"):
         rebuild_server = fakes.FakeServer('1234', '', 'REBUILD')
         active_server = fakes.FakeServer('1234', '', 'ACTIVE')
         fake_floating_ip = fakes.FakeFloatingIP('1234', 'ippool',
                                                 '1.1.1.1', '2.2.2.2',
                                                 '5678')
         config = {
             "servers.rebuild.return_value": rebuild_server,
             "servers.list.return_value": [active_server],
             "floating_ips.list.return_value": [fake_floating_ip]
         }
         OpenStackCloud.nova_client = Mock(**config)
         self.cloud.name = 'cloud-name'
         self.assertEqual(
             self.cloud._normalize_server(meta.obj_to_dict(active_server)),
             self.cloud.rebuild_server("1234", "b", wait=True))
예제 #18
0
 def test_create_server_no_wait(self):
     """
     Test that create_server with no wait and no exception in the
     novaclient create call returns the server instance.
     """
     with patch("shade.OpenStackCloud.nova_client"):
         fake_server = fakes.FakeServer('1234', '', 'BUILD')
         fake_floating_ip = fakes.FakeFloatingIP('1234', 'ippool',
                                                 '1.1.1.1', '2.2.2.2',
                                                 '5678')
         config = {
             "servers.create.return_value": fake_server,
             "servers.get.return_value": fake_server,
             "floating_ips.list.return_value": [fake_floating_ip]
         }
         OpenStackCloud.nova_client = Mock(**config)
         self.assertEqual(
             self.cloud._normalize_server(meta.obj_to_dict(fake_server)),
             self.cloud.create_server(name='server-name',
                                      image=dict(id='image=id'),
                                      flavor=dict(id='flavor-id')))
예제 #19
0
 def test_create_server_wait_server_error(self, mock_nova):
     """
     Test that a server error while waiting for the server to spawn
     raises an exception in create_server.
     """
     build_server = fakes.FakeServer('1234', '', 'BUILD')
     error_server = fakes.FakeServer('1234', '', 'ERROR')
     fake_floating_ip = fakes.FakeFloatingIP('1234', 'ippool', '1.1.1.1',
                                             '2.2.2.2', '5678')
     mock_nova.servers.create.return_value = build_server
     mock_nova.servers.get.return_value = build_server
     mock_nova.servers.list.side_effect = [[build_server], [error_server]]
     self.register_uris([
         dict(method='GET',
              uri=self.get_mock_url('network',
                                    'public',
                                    append=['v2.0', 'networks.json']),
              json={'networks': []}),
         dict(method='GET',
              uri=self.get_mock_url('network',
                                    'public',
                                    append=['v2.0', 'ports.json'],
                                    qs_elements=['device_id=1234']),
              json={'ports': []}),
         dict(method='GET',
              uri=self.get_mock_url('network',
                                    'public',
                                    append=['v2.0', 'floatingips.json']),
              json={'floatingips': [fake_floating_ip]})
     ])
     self.assertRaises(exc.OpenStackCloudException,
                       self.cloud.create_server,
                       'server-name',
                       dict(id='image-id'),
                       dict(id='flavor-id'),
                       wait=True)
     # TODO(slaweq): change do_count to True when all nova mocks will be
     # replaced with request_mocks also
     self.assert_calls(do_count=False)
예제 #20
0
 def test_rebuild_server_with_admin_pass_wait(self, mock_nova):
     """
     Test that a server with an admin_pass passed returns the password
     """
     rebuild_server = fakes.FakeServer('1234', '', 'REBUILD',
                                       adminPass='******')
     active_server = fakes.FakeServer('1234', '', 'ACTIVE')
     ret_active_server = fakes.FakeServer('1234', '', 'ACTIVE',
                                          adminPass='******')
     fake_floating_ip = fakes.FakeFloatingIP('1234', 'ippool',
                                             '1.1.1.1', '2.2.2.2',
                                             '5678')
     mock_nova.servers.rebuild.return_value = rebuild_server
     mock_nova.servers.list.return_value = [active_server]
     # TODO(slaweq): change this to neutron floating ips and turn neutron
     # back on for this test when you get to floating ips
     mock_nova.floating_ips.list.return_value = [fake_floating_ip]
     self.cloud.name = 'cloud-name'
     self.assertEqual(
         self.cloud._normalize_server(
             meta.obj_to_dict(ret_active_server)),
         self.cloud.rebuild_server(
             "1234", "b", wait=True, admin_pass='******'))
예제 #21
0
 def test_create_server_wait_server_error(self):
     """
     Test that a server error while waiting for the server to spawn
     raises an exception in create_server.
     """
     with patch("shade.OpenStackCloud.nova_client"):
         build_server = fakes.FakeServer('1234', '', 'BUILD')
         error_server = fakes.FakeServer('1234', '', 'ERROR')
         fake_floating_ip = fakes.FakeFloatingIP('1234', 'ippool',
                                                 '1.1.1.1', '2.2.2.2',
                                                 '5678')
         config = {
             "servers.create.return_value": build_server,
             "servers.get.return_value": build_server,
             "servers.list.side_effect": [[build_server], [error_server]],
             "floating_ips.list.return_value": [fake_floating_ip]
         }
         OpenStackCloud.nova_client = Mock(**config)
         self.assertRaises(OpenStackCloudException,
                           self.cloud.create_server,
                           'server-name',
                           dict(id='image-id'),
                           dict(id='flavor-id'),
                           wait=True)