Пример #1
0
    def setUp(self):
        super(TestNovaNetwork, self).setUp()

        self.nova_mock_client = mock.MagicMock()

        self.nova_client_patch = mockpatch.PatchObject(
            nova_client,
            'Client',
            new=self.nova_mock_client)

        self.fake_cloud = mock.Mock()

        self.useFixture(self.nova_client_patch)
        self.nova_network_client = NovaNetwork(FAKE_CONFIG, self.fake_cloud)

        self.sg1 = mock.Mock()
        self.sg1.name = 'fake_name_1'
        self.sg1.description = 'fake_description_1'

        self.sg2 = mock.Mock()
        self.sg2.name = 'fake_name_2'
        self.sg2.description = 'fake_description_2'
        self.sg2.rules = []

        self.fake_instance = mock.Mock()
Пример #2
0
class TestNovaNetwork(test.TestCase):
    def setUp(self):
        super(TestNovaNetwork, self).setUp()

        self.nova_mock_client = mock.MagicMock()

        self.nova_client_patch = mockpatch.PatchObject(nova_client, "Client", new=self.nova_mock_client)

        self.fake_cloud = mock.Mock()

        self.useFixture(self.nova_client_patch)
        self.nova_network_client = NovaNetwork(FAKE_CONFIG, self.fake_cloud)

        self.sg1 = mock.Mock()
        self.sg1.name = "fake_name_1"
        self.sg1.description = "fake_description_1"

        self.sg2 = mock.Mock()
        self.sg2.name = "fake_name_2"
        self.sg2.description = "fake_description_2"
        self.sg2.rules = []

        self.fake_instance = mock.Mock()

    def test_get_client(self):
        self.nova_mock_client.reset_mock()
        client = self.nova_network_client.get_client()
        self.nova_mock_client.assert_called_once_with(
            FAKE_CONFIG.cloud.user,
            FAKE_CONFIG.cloud.password,
            FAKE_CONFIG.cloud.tenant,
            FAKE_CONFIG.cloud.auth_url,
            cacert=FAKE_CONFIG.cloud.cacert,
            insecure=FAKE_CONFIG.cloud.insecure,
            region_name=FAKE_CONFIG.cloud.region,
        )

        self.assertEquals(self.nova_mock_client(), client)

    def test_get_security_groups(self):
        fake_security_groups = [self.sg1, self.sg2]
        self.nova_mock_client().security_groups.list.return_value = fake_security_groups
        security_groups = self.nova_network_client.get_security_groups()

        result = [x.__dict__ for x in fake_security_groups]

        self.assertEquals(result, security_groups)

    @mock.patch("cloudferrylib.os.network.nova_network.NovaNetwork." "get_security_groups")
    def test_upload_security_groups(self, mock_get):
        fake_existing_groups = [self.sg1]
        fake_security_groups = [self.sg1, self.sg2]
        mock_get.return_value = fake_existing_groups

        self.nova_network_client.upload_security_groups(fake_security_groups)

        kwargs = {"name": "fake_name_2", "description": "fake_description_2"}

        self.nova_mock_client().security_groups.create.assert_called_once_with(**kwargs)
Пример #3
0
    def setUp(self):
        super(TestNovaNetwork, self).setUp()

        self.nova_mock_client = mock.MagicMock()

        self.nova_client_patch = mockpatch.PatchObject(
            nova_client,
            'Client',
            new=self.nova_mock_client)

        self.fake_cloud = mock.Mock()

        self.useFixture(self.nova_client_patch)
        self.nova_network_client = NovaNetwork(FAKE_CONFIG, self.fake_cloud)

        self.sg1 = mock.Mock()
        self.sg1.name = 'fake_name_1'
        self.sg1.description = 'fake_description_1'

        self.sg2 = mock.Mock()
        self.sg2.name = 'fake_name_2'
        self.sg2.description = 'fake_description_2'
        self.sg2.rules = []

        self.fake_instance = mock.Mock()
Пример #4
0
class TestNovaNetwork(test.TestCase):
    def setUp(self):
        super(TestNovaNetwork, self).setUp()

        self.nova_mock_client = mock.MagicMock()

        self.nova_client_patch = mockpatch.PatchObject(nova_client,
                                                       'Client',
                                                       new=self.nova_mock_client)

        self.useFixture(self.nova_client_patch)
        self.nova_network_client = NovaNetwork(FAKE_CONFIG)

        self.sg1 = mock.Mock()
        self.sg1.name = 'fake_name_1'
        self.sg1.description = 'fake_description_1'

        self.sg2 = mock.Mock()
        self.sg2.name = 'fake_name_2'
        self.sg2.description = 'fake_description_2'
        self.sg2.rules = []

        self.fake_instance = mock.Mock()


    def test_get_client(self):
        self.nova_mock_client.reset_mock()
        args = (FAKE_CONFIG['user'],
                FAKE_CONFIG['password'],
                FAKE_CONFIG['tenant'],
                "http://" + FAKE_CONFIG['host'] + ":35357/v2.0/")
        client = self.nova_network_client.get_client()
        self.nova_mock_client.assert_called_once_with(*args)

        self.assertEquals(self.nova_mock_client(), client)

    def test_get_security_groups(self):
        fake_security_groups = [self.sg1, self.sg2]
        self.nova_mock_client().security_groups.list.return_value = fake_security_groups
        security_groups = self.nova_network_client.get_security_groups()

        self.assertEquals(fake_security_groups, security_groups)
    
    def test_get_networks(self):
        fake_networks = [{'name': 'fake_name', 'ip': 'fake_ip', 'mac': 'fake_mac'},]

        self.fake_instance.networks.items.return_value = ([ 'fake_name', ['fake_ip',] ],)
        self.nova_network_client.get_mac_addresses = lambda x: iter(('fake_mac',))
        
        networks = self.nova_network_client.get_networks(self.fake_instance)

        self.assertEquals(fake_networks, networks)
   
    def test_upload_security_groups(self):
        fake_existing_groups = [self.sg1]
        fake_security_groups = [self.sg1, self.sg2]
        self.nova_mock_client().security_groups.list.return_value = fake_existing_groups
        
        self.nova_network_client.upload_security_groups(fake_security_groups)
        
        kwargs = {'name': 'fake_name_2',
                  'description': 'fake_description_2'}

        self.nova_mock_client().security_groups.create.assert_called_once_with(**kwargs)
Пример #5
0
class TestNovaNetwork(test.TestCase):
    def setUp(self):
        super(TestNovaNetwork, self).setUp()

        self.nova_mock_client = mock.MagicMock()

        self.nova_client_patch = mockpatch.PatchObject(
            nova_client,
            'Client',
            new=self.nova_mock_client)

        self.fake_cloud = mock.Mock()

        self.useFixture(self.nova_client_patch)
        self.nova_network_client = NovaNetwork(FAKE_CONFIG, self.fake_cloud)

        self.sg1 = mock.Mock()
        self.sg1.name = 'fake_name_1'
        self.sg1.description = 'fake_description_1'

        self.sg2 = mock.Mock()
        self.sg2.name = 'fake_name_2'
        self.sg2.description = 'fake_description_2'
        self.sg2.rules = []

        self.fake_instance = mock.Mock()

    def test_get_client(self):
        self.nova_mock_client.reset_mock()
        args = (FAKE_CONFIG.cloud.user,
                FAKE_CONFIG.cloud.password,
                FAKE_CONFIG.cloud.tenant,
                FAKE_CONFIG.cloud.auth_url)
        client = self.nova_network_client.get_client()
        self.nova_mock_client.assert_called_once_with(*args)

        self.assertEquals(self.nova_mock_client(), client)

    def test_get_security_groups(self):
        fake_security_groups = [self.sg1, self.sg2]
        self.nova_mock_client().security_groups.list.return_value = (
            fake_security_groups)
        security_groups = self.nova_network_client.get_security_groups()

        result = [x.__dict__ for x in fake_security_groups]

        self.assertEquals(result, security_groups)

    @mock.patch('cloudferrylib.os.network.nova_network.NovaNetwork.'
                'get_security_groups')
    def test_upload_security_groups(self, mock_get):
        fake_existing_groups = [self.sg1]
        fake_security_groups = [self.sg1, self.sg2]
        mock_get.return_value = fake_existing_groups

        self.nova_network_client.upload_security_groups(fake_security_groups)

        kwargs = {'name': 'fake_name_2',
                  'description': 'fake_description_2'}

        self.nova_mock_client().security_groups.create.assert_called_once_with(
            **kwargs)
Пример #6
0
class TestNovaNetwork(test.TestCase):
    def setUp(self):
        super(TestNovaNetwork, self).setUp()

        self.nova_mock_client = mock.MagicMock()

        self.nova_client_patch = mockpatch.PatchObject(
            nova_client,
            'Client',
            new=self.nova_mock_client)

        self.fake_cloud = mock.Mock()

        self.useFixture(self.nova_client_patch)
        self.nova_network_client = NovaNetwork(FAKE_CONFIG, self.fake_cloud)

        self.sg1 = mock.Mock()
        self.sg1.name = 'fake_name_1'
        self.sg1.description = 'fake_description_1'

        self.sg2 = mock.Mock()
        self.sg2.name = 'fake_name_2'
        self.sg2.description = 'fake_description_2'
        self.sg2.rules = []

        self.fake_instance = mock.Mock()

    def test_get_client(self):
        self.nova_mock_client.reset_mock()
        args = (FAKE_CONFIG.cloud.user,
                FAKE_CONFIG.cloud.password,
                FAKE_CONFIG.cloud.tenant,
                FAKE_CONFIG.cloud.auth_url)
        client = self.nova_network_client.get_client()
        self.nova_mock_client.assert_called_once_with(*args)

        self.assertEquals(self.nova_mock_client(), client)

    def test_get_security_groups(self):
        fake_security_groups = [self.sg1, self.sg2]
        self.nova_mock_client().security_groups.list.return_value = (
            fake_security_groups)
        security_groups = self.nova_network_client.get_security_groups()

        result = [x.__dict__ for x in fake_security_groups]

        self.assertEquals(result, security_groups)

    @mock.patch('cloudferrylib.os.network.nova_network.NovaNetwork.'
                'get_security_groups')
    def test_upload_security_groups(self, mock_get):
        fake_existing_groups = [self.sg1]
        fake_security_groups = [self.sg1, self.sg2]
        mock_get.return_value = fake_existing_groups

        self.nova_network_client.upload_security_groups(fake_security_groups)

        kwargs = {'name': 'fake_name_2',
                  'description': 'fake_description_2'}

        self.nova_mock_client().security_groups.create.assert_called_once_with(
            **kwargs)