• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python shade.OpenStackCloud类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中shade.OpenStackCloud的典型用法代码示例。如果您正苦于以下问题:Python OpenStackCloud类的具体用法?Python OpenStackCloud怎么用?Python OpenStackCloud使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了OpenStackCloud类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: TestFloatingIPPool

class TestFloatingIPPool(base.TestCase):
    mock_pools = [
        {'id': 'pool1_id', 'name': 'pool1'},
        {'id': 'pool2_id', 'name': 'pool2'}]

    def setUp(self):
        super(TestFloatingIPPool, self).setUp()
        self.client = OpenStackCloud('cloud', {})

    @patch.object(OpenStackCloud, '_has_nova_extension')
    @patch.object(OpenStackCloud, 'nova_client')
    def test_list_floating_ip_pools(
            self, mock_nova_client, mock__has_nova_extension):
        mock_nova_client.floating_ip_pools.list.return_value = [
            FakeFloatingIPPool(**p) for p in self.mock_pools
        ]
        mock__has_nova_extension.return_value = True

        floating_ip_pools = self.client.list_floating_ip_pools()

        self.assertItemsEqual(floating_ip_pools, self.mock_pools)

    @patch.object(OpenStackCloud, '_has_nova_extension')
    @patch.object(OpenStackCloud, 'nova_client')
    def test_list_floating_ip_pools_exception(
            self, mock_nova_client, mock__has_nova_extension):
        mock_nova_client.floating_ip_pools.list.side_effect = \
            Exception('whatever')
        mock__has_nova_extension.return_value = True

        self.assertRaises(
            OpenStackCloudException, self.client.list_floating_ip_pools)
开发者ID:vaibhavmital,项目名称:shade,代码行数:32,代码来源:test_floating_ip_pool.py


示例2: TestFloatingIPPool

class TestFloatingIPPool(base.TestCase):
    mock_pools = [{"id": "pool1_id", "name": "pool1"}, {"id": "pool2_id", "name": "pool2"}]

    def setUp(self):
        super(TestFloatingIPPool, self).setUp()
        config = os_client_config.OpenStackConfig()
        self.client = OpenStackCloud(cloud_config=config.get_one_cloud())

    @patch.object(OpenStackCloud, "_has_nova_extension")
    @patch.object(OpenStackCloud, "nova_client")
    def test_list_floating_ip_pools(self, mock_nova_client, mock__has_nova_extension):
        mock_nova_client.floating_ip_pools.list.return_value = [FakeFloatingIPPool(**p) for p in self.mock_pools]
        mock__has_nova_extension.return_value = True

        floating_ip_pools = self.client.list_floating_ip_pools()

        self.assertItemsEqual(floating_ip_pools, self.mock_pools)

    @patch.object(OpenStackCloud, "_has_nova_extension")
    @patch.object(OpenStackCloud, "nova_client")
    def test_list_floating_ip_pools_exception(self, mock_nova_client, mock__has_nova_extension):
        mock_nova_client.floating_ip_pools.list.side_effect = Exception("whatever")
        mock__has_nova_extension.return_value = True

        self.assertRaises(OpenStackCloudException, self.client.list_floating_ip_pools)
开发者ID:jsmartin,项目名称:shade,代码行数:25,代码来源:test_floating_ip_pool.py


示例3: TestShade

class TestShade(base.TestCase):
    def setUp(self):
        super(TestShade, self).setUp()
        self.cloud = OpenStackCloud("cloud", {})

    @mock.patch.object(swift_client, "Connection")
    @mock.patch.object(shade.OpenStackCloud, "auth_token", new_callable=mock.PropertyMock)
    @mock.patch.object(shade.OpenStackCloud, "get_session_endpoint")
    def test_swift_client(self, endpoint_mock, auth_mock, swift_mock):
        endpoint_mock.return_value = "danzig"
        auth_mock.return_value = "yankee"
        self.cloud.swift_client
        swift_mock.assert_called_with(
            preauthurl="danzig",
            preauthtoken="yankee",
            auth_version="2",
            os_options=dict(object_storage_url="danzig", auth_token="yankee", region_name=""),
        )

    @mock.patch.object(shade.OpenStackCloud, "auth_token", new_callable=mock.PropertyMock)
    @mock.patch.object(shade.OpenStackCloud, "get_session_endpoint")
    def test_swift_client_no_endpoint(self, endpoint_mock, auth_mock):
        endpoint_mock.side_effect = KeyError
        auth_mock.return_value = "quebec"
        e = self.assertRaises(exc.OpenStackCloudException, lambda: self.cloud.swift_client)
        self.assertIn("Error constructing swift client", str(e))

    @mock.patch.object(shade.OpenStackCloud, "auth_token")
    @mock.patch.object(shade.OpenStackCloud, "get_session_endpoint")
    def test_swift_service(self, endpoint_mock, auth_mock):
        endpoint_mock.return_value = "slayer"
        auth_mock.return_value = "zulu"
        self.assertIsInstance(self.cloud.swift_service, swift_service.SwiftService)
        endpoint_mock.assert_called_with(service_key="object-store")

    @mock.patch.object(shade.OpenStackCloud, "get_session_endpoint")
    def test_swift_service_no_endpoint(self, endpoint_mock):
        endpoint_mock.side_effect = KeyError
        e = self.assertRaises(exc.OpenStackCloudException, lambda: self.cloud.swift_service)
        self.assertIn("Error constructing swift client", str(e))

    @mock.patch.object(shade.OpenStackCloud, "swift_client")
    def test_get_object_segment_size(self, swift_mock):
        swift_mock.get_capabilities.return_value = {"swift": {"max_file_size": 1000}}
        self.assertEqual(900, self.cloud.get_object_segment_size(900))
        self.assertEqual(1000, self.cloud.get_object_segment_size(1000))
        self.assertEqual(1000, self.cloud.get_object_segment_size(1100))
开发者ID:adreznec,项目名称:shade,代码行数:47,代码来源:test_object.py


示例4: TestDeleteServer

class TestDeleteServer(base.TestCase):

    def setUp(self):
        super(TestDeleteServer, self).setUp()
        self.cloud = OpenStackCloud("cloud", {})

    @mock.patch('shade.OpenStackCloud.nova_client')
    def test_delete_server(self, nova_mock):
        """
        Test that novaclient server delete is called when wait=False
        """
        server = mock.MagicMock(id='1234',
                                status='ACTIVE')
        server.name = 'daffy'
        nova_mock.servers.list.return_value = [server]
        self.cloud.delete_server('daffy', wait=False)
        nova_mock.servers.delete.assert_called_with(server=server)

    @mock.patch('shade.OpenStackCloud.nova_client')
    def test_delete_server_already_gone(self, nova_mock):
        """
        Test that we return immediately when server is already gone
        """
        nova_mock.servers.list.return_value = []
        self.cloud.delete_server('tweety', wait=False)
        self.assertFalse(nova_mock.servers.delete.called)

    @mock.patch('shade.OpenStackCloud.nova_client')
    def test_delete_server_already_gone_wait(self, nova_mock):
        self.cloud.delete_server('speedy', wait=True)
        self.assertFalse(nova_mock.servers.delete.called)

    @mock.patch('shade.OpenStackCloud.nova_client')
    def test_delete_server_wait_for_notfound(self, nova_mock):
        """
        Test that delete_server waits for NotFound from novaclient
        """
        server = mock.MagicMock(id='9999',
                                status='ACTIVE')
        server.name = 'wily'
        nova_mock.servers.list.return_value = [server]

        def _delete_wily(*args, **kwargs):
            self.assertIn('server', kwargs)
            self.assertEqual('9999', kwargs['server'].id)
            nova_mock.servers.list.return_value = []

            def _raise_notfound(*args, **kwargs):
                self.assertIn('server', kwargs)
                self.assertEqual('9999', kwargs['server'].id)
                raise nova_exc.NotFound(code='404')
            nova_mock.servers.get.side_effect = _raise_notfound

        nova_mock.servers.delete.side_effect = _delete_wily
        self.cloud.delete_server('wily', wait=True)
        nova_mock.servers.delete.assert_called_with(server=server)
开发者ID:emonty,项目名称:shade,代码行数:56,代码来源:test_delete_server.py


示例5: setUp

    def setUp(self):
        super(TestFloatingIP, self).setUp()
        # floating_ip_source='neutron' is default for OpenStackCloud()
        config = os_client_config.OpenStackConfig()
        self.client = OpenStackCloud(
            cloud_config=config.get_one_cloud(validate=False))

        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_neutron_floating_ips(
            self.mock_floating_ip_list_rep['floatingips'])[0]
开发者ID:erickcantwell,项目名称:shade,代码行数:18,代码来源:test_floating_ip_neutron.py


示例6: setUp

 def setUp(self):
     super(TestDeleteVolumeSnapshot, self).setUp()
     config = os_client_config.OpenStackConfig()
     self.client = OpenStackCloud(
         cloud_config=config.get_one_cloud(validate=False))
开发者ID:LIP-Computing,项目名称:shade,代码行数:5,代码来源:test_delete_volume_snapshot.py


示例7: setUp

 def setUp(self):
     super(TestFloatingIP, self).setUp()
     # floating_ip_source='neutron' is default for OpenStackCloud()
     self.client = OpenStackCloud("cloud", {})
开发者ID:chrismeyersfsu,项目名称:shade,代码行数:4,代码来源:test_floating_ip_neutron.py


示例8: setUp

 def setUp(self):
     super(TestObject, self).setUp()
     config = os_client_config.OpenStackConfig()
     self.cloud = OpenStackCloud(
         cloud_config=config.get_one_cloud(validate=False))
开发者ID:syseleven,项目名称:shade,代码行数:5,代码来源:test_object.py


示例9: TestDeleteVolumeSnapshot

class TestDeleteVolumeSnapshot(base.TestCase):

    def setUp(self):
        super(TestDeleteVolumeSnapshot, self).setUp()
        config = os_client_config.OpenStackConfig()
        self.client = OpenStackCloud(
            cloud_config=config.get_one_cloud(validate=False))

    @patch.object(OpenStackCloud, 'cinder_client')
    def test_delete_volume_snapshot(self, mock_cinder):
        """
        Test that delete_volume_snapshot without a wait returns True instance
        when the volume snapshot deletes.
        """
        fake_snapshot = fakes.FakeVolumeSnapshot('1234', 'available',
                                                 'foo', 'derpysnapshot')

        mock_cinder.volume_snapshots.list.return_value = [fake_snapshot]

        self.assertEqual(
            True,
            self.client.delete_volume_snapshot(name_or_id='1234', wait=False)
        )

        mock_cinder.volume_snapshots.list.assert_called_with(detailed=True,
                                                             search_opts=None)

    @patch.object(OpenStackCloud, 'cinder_client')
    def test_delete_volume_snapshot_with_error(self, mock_cinder):
        """
        Test that a exception while deleting a volume snapshot will cause an
        OpenStackCloudException.
        """
        fake_snapshot = fakes.FakeVolumeSnapshot('1234', 'available',
                                                 'foo', 'derpysnapshot')

        mock_cinder.volume_snapshots.delete.side_effect = Exception(
            "exception")
        mock_cinder.volume_snapshots.list.return_value = [fake_snapshot]

        self.assertRaises(
            OpenStackCloudException,
            self.client.delete_volume_snapshot, name_or_id='1234',
            wait=True, timeout=1)

        mock_cinder.volume_snapshots.delete.assert_called_with(
            snapshot='1234')

    @patch.object(OpenStackCloud, 'cinder_client')
    def test_delete_volume_snapshot_with_timeout(self, mock_cinder):
        """
        Test that a timeout while waiting for the volume snapshot to delete
        raises an exception in delete_volume_snapshot.
        """
        fake_snapshot = fakes.FakeVolumeSnapshot('1234', 'available',
                                                 'foo', 'derpysnapshot')

        mock_cinder.volume_snapshots.list.return_value = [fake_snapshot]

        self.assertRaises(
            OpenStackCloudTimeout,
            self.client.delete_volume_snapshot, name_or_id='1234',
            wait=True, timeout=1)

        mock_cinder.volume_snapshots.list.assert_called_with(detailed=True,
                                                             search_opts=None)
开发者ID:LIP-Computing,项目名称:shade,代码行数:66,代码来源:test_delete_volume_snapshot.py


示例10: TestRebuildServer

class TestRebuildServer(base.TestCase):

    def setUp(self):
        super(TestRebuildServer, self).setUp()
        config = os_client_config.OpenStackConfig()
        self.client = OpenStackCloud(
            cloud_config=config.get_one_cloud(validate=False))

    def test_rebuild_server_rebuild_exception(self):
        """
        Test that an exception in the novaclient rebuild raises an exception in
        rebuild_server.
        """
        with patch("shade.OpenStackCloud"):
            config = {
                "servers.rebuild.side_effect": Exception("exception"),
            }
            OpenStackCloud.nova_client = Mock(**config)
            self.assertRaises(
                OpenStackCloudException, self.client.rebuild_server, "a", "b")

    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')
        with patch("shade.OpenStackCloud"):
            config = {
                "servers.rebuild.return_value": rebuild_server,
                "servers.get.return_value": error_server,
            }
            OpenStackCloud.nova_client = Mock(**config)
            self.assertRaises(
                OpenStackCloudException,
                self.client.rebuild_server, "a", "b", wait=True)

    def test_rebuild_server_timeout(self):
        """
        Test that a timeout while waiting for the server to rebuild raises an
        exception in rebuild_server.
        """
        rebuild_server = fakes.FakeServer('1234', '', 'REBUILD')
        with patch("shade.OpenStackCloud"):
            config = {
                "servers.rebuild.return_value": rebuild_server,
                "servers.get.return_value": rebuild_server,
            }
            OpenStackCloud.nova_client = Mock(**config)
            self.assertRaises(
                OpenStackCloudTimeout,
                self.client.rebuild_server, "a", "b", wait=True, timeout=0.001)

    def test_rebuild_server_no_wait(self):
        """
        Test that rebuild_server with no wait and no exception in the
        novaclient rebuild call returns the server instance.
        """
        with patch("shade.OpenStackCloud"):
            rebuild_server = fakes.FakeServer('1234', '', 'REBUILD')
            config = {
                "servers.rebuild.return_value": rebuild_server
            }
            OpenStackCloud.nova_client = Mock(**config)
            self.assertEqual(meta.obj_to_dict(rebuild_server),
                             self.client.rebuild_server("a", "b"))

    def test_rebuild_server_with_admin_pass_no_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='ooBootheiX0edoh')
            config = {
                "servers.rebuild.return_value": rebuild_server,
            }
            OpenStackCloud.nova_client = Mock(**config)
            self.assertEqual(
                meta.obj_to_dict(rebuild_server),
                self.client.rebuild_server('a', 'b',
                                           admin_pass='ooBootheiX0edoh'))

    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='ooBootheiX0edoh')
            active_server = fakes.FakeServer('1234', '', 'ACTIVE')
            ret_active_server = fakes.FakeServer('1234', '', 'ACTIVE',
                                                 adminPass='ooBootheiX0edoh')
            config = {
                "servers.rebuild.return_value": rebuild_server,
                "servers.get.return_value": active_server,
            }
            OpenStackCloud.nova_client = Mock(**config)
            self.client.name = 'cloud-name'
#.........这里部分代码省略.........
开发者ID:LIP-Computing,项目名称:shade,代码行数:101,代码来源:test_rebuild_server.py


示例11: setUp

 def setUp(self):
     super(TestCreateServer, self).setUp()
     config = os_client_config.OpenStackConfig()
     self.client = OpenStackCloud(
         cloud_config=config.get_one_cloud(validate=False))
     self.client._SERVER_AGE = 0
开发者ID:LIP-Computing,项目名称:shade,代码行数:6,代码来源:test_create_server.py


示例12: TestDeleteServer

class TestDeleteServer(base.TestCase):
    novaclient_exceptions = (nova_exc.BadRequest,
                             nova_exc.Unauthorized,
                             nova_exc.Forbidden,
                             nova_exc.MethodNotAllowed,
                             nova_exc.Conflict,
                             nova_exc.OverLimit,
                             nova_exc.RateLimit,
                             nova_exc.HTTPNotImplemented)

    def setUp(self):
        super(TestDeleteServer, self).setUp()
        self.cloud = OpenStackCloud("cloud", {})

    @mock.patch('shade.OpenStackCloud.nova_client')
    def test_delete_server(self, nova_mock):
        """
        Test that novaclient server delete is called when wait=False
        """
        server = fakes.FakeServer('1234', 'daffy', 'ACTIVE')
        nova_mock.servers.list.return_value = [server]
        self.cloud.delete_server('daffy', wait=False)
        nova_mock.servers.delete.assert_called_with(server=server.id)

    @mock.patch('shade.OpenStackCloud.nova_client')
    def test_delete_server_already_gone(self, nova_mock):
        """
        Test that we return immediately when server is already gone
        """
        nova_mock.servers.list.return_value = []
        self.cloud.delete_server('tweety', wait=False)
        self.assertFalse(nova_mock.servers.delete.called)

    @mock.patch('shade.OpenStackCloud.nova_client')
    def test_delete_server_already_gone_wait(self, nova_mock):
        self.cloud.delete_server('speedy', wait=True)
        self.assertFalse(nova_mock.servers.delete.called)

    @mock.patch('shade.OpenStackCloud.nova_client')
    def test_delete_server_wait_for_notfound(self, nova_mock):
        """
        Test that delete_server waits for NotFound from novaclient
        """
        server = fakes.FakeServer('9999', 'wily', 'ACTIVE')
        nova_mock.servers.list.return_value = [server]

        def _delete_wily(*args, **kwargs):
            self.assertIn('server', kwargs)
            self.assertEqual('9999', kwargs['server'])
            nova_mock.servers.list.return_value = []

            def _raise_notfound(*args, **kwargs):
                self.assertIn('server', kwargs)
                self.assertEqual('9999', kwargs['server'])
                raise nova_exc.NotFound(code='404')
            nova_mock.servers.get.side_effect = _raise_notfound

        nova_mock.servers.delete.side_effect = _delete_wily
        self.cloud.delete_server('wily', wait=True)
        nova_mock.servers.delete.assert_called_with(server=server.id)

    @mock.patch('shade.OpenStackCloud.nova_client')
    def test_delete_server_fails(self, nova_mock):
        """
        Test that delete_server wraps novaclient exceptions
        """
        nova_mock.servers.list.return_value = [fakes.FakeServer('1212',
                                                                'speedy',
                                                                'ACTIVE')]
        for fail in self.novaclient_exceptions:

            def _raise_fail(server):
                raise fail(code=fail.http_status)

            nova_mock.servers.delete.side_effect = _raise_fail
            exc = self.assertRaises(shade_exc.OpenStackCloudException,
                                    self.cloud.delete_server, 'speedy',
                                    wait=False)
            # Note that message is deprecated from Exception, but not in
            # the novaclient exceptions.
            self.assertIn(fail.message, str(exc))

    @mock.patch('shade.OpenStackCloud.nova_client')
    def test_delete_server_get_fails(self, nova_mock):
        """
        Test that delete_server wraps novaclient exceptions on wait fails
        """
        nova_mock.servers.list.return_value = [fakes.FakeServer('2000',
                                                                'yosemite',
                                                                'ACTIVE')]
        for fail in self.novaclient_exceptions:

            def _raise_fail(server):
                raise fail(code=fail.http_status)

            nova_mock.servers.get.side_effect = _raise_fail
            exc = self.assertRaises(shade_exc.OpenStackCloudException,
                                    self.cloud.delete_server, 'yosemite',
                                    wait=True)
            # Note that message is deprecated from Exception, but not in
#.........这里部分代码省略.........
开发者ID:vaibhavmital,项目名称:shade,代码行数:101,代码来源:test_delete_server.py


示例13: setUp

 def setUp(self):
     super(TestPort, self).setUp()
     self.client = OpenStackCloud('cloud', {})
开发者ID:vaibhavmital,项目名称:shade,代码行数:3,代码来源:test_port.py


示例14: TestFloatingIP

class TestFloatingIP(base.TestCase):
    mock_floating_ip_list_rep = {
        'floatingips': [
            {
                'router_id': 'd23abc8d-2991-4a55-ba98-2aaea84cc72f',
                'tenant_id': '4969c491a3c74ee4af974e6d800c62de',
                'floating_network_id': '376da547-b977-4cfe-9cba-275c80debf57',
                'fixed_ip_address': '192.0.2.29',
                'floating_ip_address': '203.0.113.29',
                'port_id': 'ce705c24-c1ef-408a-bda3-7bbd946164ab',
                'id': '2f245a7b-796b-4f26-9cf9-9e82d248fda7',
                'status': 'ACTIVE'
            },
            {
                'router_id': None,
                'tenant_id': '4969c491a3c74ee4af974e6d800c62de',
                'floating_network_id': '376da547-b977-4cfe-9cba-275c80debf57',
                'fixed_ip_address': None,
                'floating_ip_address': '203.0.113.30',
                'port_id': None,
                'id': '61cea855-49cb-4846-997d-801b70c71bdd',
                'status': 'DOWN'
            }
        ]
    }

    mock_floating_ip_new_rep = {
        'floatingip': {
            'fixed_ip_address': '10.0.0.4',
            'floating_ip_address': '172.24.4.229',
            'floating_network_id': 'my-network-id',
            'id': '2f245a7b-796b-4f26-9cf9-9e82d248fda8',
            'port_id': None,
            'router_id': None,
            'status': 'ACTIVE',
            'tenant_id': '4969c491a3c74ee4af974e6d800c62df'
        }
    }

    mock_get_network_rep = {
        'status': 'ACTIVE',
        'subnets': [
            '54d6f61d-db07-451c-9ab3-b9609b6b6f0b'
        ],
        'name': 'my-network',
        'provider:physical_network': None,
        'admin_state_up': True,
        'tenant_id': '4fd44f30292945e481c7b8a0c8908869',
        'provider:network_type': 'local',
        'router:external': True,
        'shared': True,
        'id': 'my-network-id',
        'provider:segmentation_id': None
    }

    mock_search_ports_rep = [
        {
            'status': 'ACTIVE',
            'binding:host_id': 'devstack',
            'name': 'first-port',
            'allowed_address_pairs': [],
            'admin_state_up': True,
            'network_id': '70c1db1f-b701-45bd-96e0-a313ee3430b3',
            'tenant_id': '',
            'extra_dhcp_opts': [],
            'binding:vif_details': {
                'port_filter': True,
                'ovs_hybrid_plug': True
            },
            'binding:vif_type': 'ovs',
            'device_owner': 'compute:None',
            'mac_address': 'fa:16:3e:58:42:ed',
            'binding:profile': {},
            'binding:vnic_type': 'normal',
            'fixed_ips': [
                {
                    'subnet_id': '008ba151-0b8c-4a67-98b5-0d2b87666062',
                    'ip_address': u'172.24.4.2'
                }
            ],
            'id': 'ce705c24-c1ef-408a-bda3-7bbd946164ac',
            'security_groups': [],
            'device_id': 'server_id'
        }
    ]

    def assertAreInstances(self, elements, elem_type):
        for e in elements:
            self.assertIsInstance(e, elem_type)

    def setUp(self):
        super(TestFloatingIP, self).setUp()
        # floating_ip_source='neutron' is default for OpenStackCloud()
        config = os_client_config.OpenStackConfig()
        self.client = OpenStackCloud(
            cloud_config=config.get_one_cloud(validate=False))

        self.fake_server = meta.obj_to_dict(
            fakes.FakeServer(
                'server-id', '', 'ACTIVE',
#.........这里部分代码省略.........
开发者ID:erickcantwell,项目名称:shade,代码行数:101,代码来源:test_floating_ip_neutron.py


示例15: setUp

 def setUp(self):
     super(TestPort, self).setUp()
     config = os_client_config.OpenStackConfig()
     self.client = OpenStackCloud(cloud_config=config.get_one_cloud())
开发者ID:jsmartin,项目名称:shade,代码行数:4,代码来源:test_port.py


示例16: setUp

 def setUp(self):
     super(TestFloatingIPPool, self).setUp()
     self.client = OpenStackCloud('cloud', {})
开发者ID:vaibhavmital,项目名称:shade,代码行数:3,代码来源:test_floating_ip_pool.py


示例17: setUp

 def setUp(self):
     super(TestDeleteServer, self).setUp()
     config = os_client_config.OpenStackConfig()
     self.cloud = OpenStackCloud(cloud_config=config.get_one_cloud())
开发者ID:jsmartin,项目名称:shade,代码行数:4,代码来源:test_delete_server.py


示例18: TestFloatingIP

class TestFloatingIP(base.TestCase):
    mock_floating_ip_list_rep = [
        {
            'fixed_ip': None,
            'id': 1,
            'instance_id': None,
            'ip': '203.0.113.1',
            'pool': 'nova'
        },
        {
            'fixed_ip': None,
            'id': 2,
            'instance_id': None,
            'ip': '203.0.113.2',
            'pool': 'nova'
        },
        {
            'fixed_ip': '192.0.2.3',
            'id': 29,
            'instance_id': 'myself',
            'ip': '198.51.100.29',
            'pool': 'black_hole'
        }
    ]

    def assertAreInstances(self, elements, elem_type):
        for e in elements:
            self.assertIsInstance(e, elem_type)

    def setUp(self):
        super(TestFloatingIP, self).setUp()
        self.client = OpenStackCloud("cloud", {})

    @patch.object(OpenStackCloud, 'nova_client')
    @patch.object(OpenStackCloud, 'has_service')
    def test_list_floating_ips(self, mock_has_service, mock_nova_client):
        mock_has_service.side_effect = has_service_side_effect
        mock_nova_client.floating_ips.list.return_value = [
            FakeFloatingIP(**ip) for ip in self.mock_floating_ip_list_rep
        ]

        floating_ips = self.client.list_floating_ips()

        mock_nova_client.floating_ips.list.assert_called_with()
        self.assertIsInstance(floating_ips, list)
        self.assertEqual(3, len(floating_ips))
        self.assertAreInstances(floating_ips, dict)

    @patch.object(OpenStackCloud, 'nova_client')
    @patch.object(OpenStackCloud, 'has_service')
    def test_search_floating_ips(self, mock_has_service, mock_nova_client):
        mock_has_service.side_effect = has_service_side_effect
        mock_nova_client.floating_ips.list.return_value = [
            FakeFloatingIP(**ip) for ip in self.mock_floating_ip_list_rep
        ]

        floating_ips = self.client.search_floating_ips(
            filters={'attached': False})

        mock_nova_client.floating_ips.list.assert_called_with()
        self.assertIsInstance(floating_ips, list)
        self.assertEqual(2, len(floating_ips))
        self.assertAreInstances(floating_ips, dict)

    @patch.object(OpenStackCloud, 'nova_client')
    @patch.object(OpenStackCloud, 'has_service')
    def test_get_floating_ip(self, mock_has_service, mock_nova_client):
        mock_has_service.side_effect = has_service_side_effect
        mock_nova_client.floating_ips.list.return_value = [
            FakeFloatingIP(**ip) for ip in self.mock_floating_ip_list_rep
        ]

        floating_ip = self.client.get_floating_ip(id='29')

        mock_nova_client.floating_ips.list.assert_called_with()
        self.assertIsInstance(floating_ip, dict)
        self.assertEqual('198.51.100.29', floating_ip['floating_ip_address'])

    @patch.object(OpenStackCloud, 'nova_client')
    @patch.object(OpenStackCloud, 'has_service')
    def test_get_floating_ip_not_found(
            self, mock_has_service, mock_nova_client):
        mock_has_service.side_effect = has_service_side_effect
        mock_nova_client.floating_ips.list.return_value = [
            FakeFloatingIP(**ip) for ip in self.mock_floating_ip_list_rep
        ]

        floating_ip = self.client.get_floating_ip(id='666')

        self.assertIsNone(floating_ip)
开发者ID:vaibhavmital,项目名称:shade,代码行数:90,代码来源:test_floating_ip_nova.py


示例19: TestCreateVolumeSnapshot

class TestCreateVolumeSnapshot(base.TestCase):
    def setUp(self):
        super(TestCreateVolumeSnapshot, self).setUp()
        config = os_client_config.OpenStackConfig()
        self.client = OpenStackCloud(cloud_config=config.get_one_cloud(validate=False))

    @patch.object(OpenStackCloud, "cinder_client")
    def test_create_volume_snapshot_wait(self, mock_cinder):
        """
        Test that create_volume_snapshot with a wait returns the volume
        snapshot when its status changes to "available".
        """
        build_snapshot = fakes.FakeVolumeSnapshot("1234", "creating", "foo", "derpysnapshot")
        fake_snapshot = fakes.FakeVolumeSnapshot("1234", "available", "foo", "derpysnapshot")

        mock_cinder.volume_snapshots.create.return_value = build_snapshot
        mock_cinder.volume_snapshots.get.return_value = fake_snapshot
        mock_cinder.volume_snapshots.list.return_value = [build_snapshot, fake_snapshot]

        self.assertEqual(
            _utils.normalize_volumes([meta.obj_to_dict(fake_snapshot)])[0],
            self.client.create_volume_snapshot(volume_id="1234", wait=True),
        )

        mock_cinder.volume_snapshots.create.assert_called_with(force=False, volume_id="1234")
        mock_cinder.volume_snapshots.get.assert_called_with(snapshot_id=meta.obj_to_dict(build_snapshot)["id"])

    @patch.object(OpenStackCloud, "cinder_client")
    def test_create_volume_snapshot_with_timeout(self, mock_cinder):
        """
        Test that a timeout while waiting for the volume snapshot to create
        raises an exception in create_volume_snapshot.
        """
        build_snapshot = fakes.FakeVolumeSnapshot("1234", "creating", "foo", "derpysnapshot")

        mock_cinder.volume_snapshots.create.return_value = build_snapshot
        mock_cinder.volume_snapshots.get.return_value = build_snapshot
        mock_cinder.volume_snapshots.list.return_value = [build_snapshot]

        self.assertRaises(
            OpenStackCloudTimeout, self.client.create_volume_snapshot, volume_id="1234", wait=True, timeout=1
        )

        mock_cinder.volume_snapshots.create.assert_called_with(force=False, volume_id="1234")
        mock_cinder.volume_snapshots.get.assert_called_with(snapshot_id=meta.obj_to_dict(build_snapshot)["id"])

    @patch.object(OpenStackCloud, "cinder_client")
    def test_create_volume_snapshot_with_error(self, mock_cinder):
        """
        Test that a error status while waiting for the volume snapshot to
        create raises an exception in create_volume_snapshot.
        """
        build_snapshot = fakes.FakeVolumeSnapshot("1234", "creating", "bar", "derpysnapshot")
        error_snapshot = fakes.FakeVolumeSnapshot("1234", "error", "blah", "derpysnapshot")

        mock_cinder.volume_snapshots.create.return_value = build_snapshot
        mock_cinder.volume_snapshots.get.return_value = error_snapshot
        mock_cinder.volume_snapshots.list.return_value = [error_snapshot]

        self.assertRaises(
            OpenStackCloudException, self.client.create_volume_snapshot, volume_id="1234", wait=True, timeout=5
        )

        mock_cinder.volume_snapshots.create.assert_called_with(force=False, volume_id="1234")
        mock_cinder.volume_snapshots.get.assert_called_with(snapshot_id=meta.obj_to_dict(build_snapshot)["id"])
开发者ID:jhedden,项目名称:shade,代码行数:65,代码来源:test_create_volume_snapshot.py


示例20: TestCreateServer

class TestCreateServer(base.TestCase):

    def setUp(self):
        super(TestCreateServer, self).setUp()
        config = os_client_config.OpenStackConfig()
        self.client = OpenStackCloud(cloud_config=config.get_one_cloud())

    def test_create_server_with_create_exception(self):
        """
        Test that an exception in the novaclient create raises an exception in
        create_server.
        """
        with patch("shade.OpenStackCloud"):
            config = {
                "servers.create.side_effect": Exception("exception"),
            }
            OpenStackCloud.nova_client = Mock(**config)
            self.assertRaises(
                OpenStackCloudException, self.client.create_server)

    def test_create_server_with_get_exception(self):
        """
        Test that an exception when attempting to get the server instance via
        the novaclient raises an exception in create_server.
        """
        with patch("shade.OpenStackCloud"):
            config = {
                "servers.create.return_value": Mock(status="BUILD"),
                "servers.get.side_effect": Exception("exception")
            }
            OpenStackCloud.nova_client = Mock(**config)
            self.assertRaises(
                OpenStackCloudException, self.client.create_server)

    def test_create_server_with_server_error(self):
        """
        Test that a server error before we return or begin waiting for the
        server instance spawn raises an exception in create_server.
        """
        with patch("shade.OpenStackCloud"):
            config = {
                "servers.create.return_value": Mock(status="BUILD"),
                "servers.get.return_value": Mock(status="ERROR")
            }
            OpenStackCloud.nova_client = Mock(**config)
            self.assertRaises(
                OpenStackCloudException, self.client.create_server)

    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"):
            config = {
                "servers.create.return_value": Mock(status="BUILD"),
                "servers.get.side_effect": [
                    Mock(status="BUILD"), Mock(status="ERROR")]
            }
            OpenStackCloud.nova_client = Mock(**config)
            self.assertRaises(
                OpenStackCloudException,
                self.client.create_server, wait=True)

    def test_create_server_with_timeout(self):
        """
        Test that a timeout while waiting for the server to spawn raises an
        exception in create_server.
        """
        with patch("shade.OpenStackCloud"):
            config = {
                "servers.create.return_value": Mock(status="BUILD"),
                "servers.get.return_value": Mock(status="BUILD")
            }
            OpenStackCloud.nova_client = Mock(**config)
            self.assertRaises(
                OpenStackCloudTimeout,
                self.client.create_server, wait=True, timeout=1)

    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"):
            fake_server = fakes.FakeServer('', '', 'BUILD')
            config = {
                "servers.create.return_value": fake_server,
                "server 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python meta.get_hostvars_from_server函数代码示例发布时间:2022-05-27
下一篇:
Python shade.operator_cloud函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap