Exemplo n.º 1
0
    def test_add_single_nic_on_vm(self, client_mock, mock_vm_set, mock_vm_get):
        #pylint: disable=line-too-long
        new_nic_name = 'new_nic'
        new_nic_id = '/subscriptions/123/resourceGroups/rg1/providers/Microsoft.Network/networkInterfaces/' + new_nic_name
        new_nic = NetworkInterfaceReference(new_nic_id, False)

        #stub to get the vm which has no nic
        vm = FakedVM()
        vm.network_profile = None
        mock_vm_get.return_value = vm

        #stub to return nic on 'get'
        network_client_fake = mock.MagicMock()
        network_client_fake.network_interfaces.get.return_value = new_nic
        client_mock.return_value = network_client_fake

        #execute
        vm_add_nics('rg1', 'vm1', [new_nic_id], [])

        #assert
        self.assertTrue(mock_vm_get.called)
        mock_vm_set.assert_called_once_with(vm)
        network_client_fake.network_interfaces.get.assert_called_once_with('rg1', new_nic_name)
        self.assertEqual(len(vm.network_profile.network_interfaces), 1)
        self.assertEqual(vm.network_profile.network_interfaces[0].id, new_nic_id)
        self.assertTrue(vm.network_profile.network_interfaces[0].primary)
Exemplo n.º 2
0
    def test_add_nics_on_vm(self, client_mock, mock_vm_set, mock_vm_get):
        #pylint: disable=line-too-long
        new_nic_name = 'new_nic'
        new_nic_id = '/subscriptions/123/resourceGroups/rg1/providers/Microsoft.Network/networkInterfaces/' + new_nic_name
        new_nic = NetworkInterfaceReference(new_nic_id, False)
        existing_nic_id = '/subscriptions/123/resourceGroups/rg1/providers/Microsoft.Network/networkInterfaces/existing_nic'
        existing_nic = NetworkInterfaceReference(existing_nic_id, True)
        existing_nic_name2 = 'existing_nic2'
        existing_nic_id2 = '/subscriptions/123/resourceGroups/rg1/providers/Microsoft.Network/networkInterfaces/' + existing_nic_name2
        existing_nic2 = NetworkInterfaceReference(existing_nic_id2, False)

        #stub to get the vm
        vm = FakedVM([existing_nic, existing_nic2])
        mock_vm_get.return_value = vm

        #stub to return nic on 'get'
        network_client_fake = mock.MagicMock()
        network_client_fake.network_interfaces.get.return_value = new_nic
        client_mock.return_value = network_client_fake

        #execute
        vm_add_nics('rg1', 'vm1', [new_nic_id], [], existing_nic_name2)

        #assert
        self.assertTrue(mock_vm_get.called)
        mock_vm_set.assert_called_once_with(vm)
        network_client_fake.network_interfaces.get.assert_called_once_with('rg1', new_nic_name)
        self.assertEqual(len(vm.network_profile.network_interfaces), 3)
        self.assertEqual(vm.network_profile.network_interfaces[0].id, existing_nic_id)
        self.assertEqual(vm.network_profile.network_interfaces[1].id, existing_nic_id2)
        self.assertEqual(vm.network_profile.network_interfaces[2].id, new_nic_id)
        self.assertFalse(vm.network_profile.network_interfaces[0].primary)
        self.assertTrue(vm.network_profile.network_interfaces[1].primary)
        self.assertFalse(vm.network_profile.network_interfaces[2].primary)
    def test_add_single_nic_on_vm(self, client_mock, mock_vm_set, mock_vm_get):
        #pylint: disable=line-too-long
        new_nic_name = 'new_nic'
        new_nic_id = '/subscriptions/123/resourceGroups/rg1/providers/Microsoft.Network/networkInterfaces/' + new_nic_name
        new_nic = NetworkInterfaceReference(new_nic_id, False)

        #stub to get the vm which has no nic
        vm = FakedVM()
        vm.network_profile = None
        mock_vm_get.return_value = vm

        #stub to return nic on 'get'
        network_client_fake = mock.MagicMock()
        network_client_fake.network_interfaces.get.return_value = new_nic
        client_mock.return_value = network_client_fake

        #execute
        vm_add_nics('rg1', 'vm1', [new_nic_id], [])

        #assert
        self.assertTrue(mock_vm_get.called)
        mock_vm_set.assert_called_once_with(vm)
        network_client_fake.network_interfaces.get.assert_called_once_with(
            'rg1', new_nic_name)
        self.assertEqual(len(vm.network_profile.network_interfaces), 1)
        self.assertEqual(vm.network_profile.network_interfaces[0].id,
                         new_nic_id)
        self.assertTrue(vm.network_profile.network_interfaces[0].primary)
    def test_add_nics_on_vm(self, client_mock, mock_vm_set, mock_vm_get):
        #pylint: disable=line-too-long
        new_nic_name = 'new_nic'
        new_nic_id = '/subscriptions/123/resourceGroups/rg1/providers/Microsoft.Network/networkInterfaces/' + new_nic_name
        new_nic = NetworkInterfaceReference(new_nic_id, False)
        existing_nic_id = '/subscriptions/123/resourceGroups/rg1/providers/Microsoft.Network/networkInterfaces/existing_nic'
        existing_nic = NetworkInterfaceReference(existing_nic_id, True)
        existing_nic_name2 = 'existing_nic2'
        existing_nic_id2 = '/subscriptions/123/resourceGroups/rg1/providers/Microsoft.Network/networkInterfaces/' + existing_nic_name2
        existing_nic2 = NetworkInterfaceReference(existing_nic_id2, False)

        #stub to get the vm
        vm = FakedVM([existing_nic, existing_nic2])
        mock_vm_get.return_value = vm

        #stub to return nic on 'get'
        network_client_fake = mock.MagicMock()
        network_client_fake.network_interfaces.get.return_value = new_nic
        client_mock.return_value = network_client_fake

        #execute
        vm_add_nics('rg1', 'vm1', [new_nic_id], [], existing_nic_name2)

        #assert
        self.assertTrue(mock_vm_get.called)
        mock_vm_set.assert_called_once_with(vm)
        network_client_fake.network_interfaces.get.assert_called_once_with(
            'rg1', new_nic_name)
        self.assertEqual(len(vm.network_profile.network_interfaces), 3)
        self.assertEqual(vm.network_profile.network_interfaces[0].id,
                         existing_nic_id)
        self.assertEqual(vm.network_profile.network_interfaces[1].id,
                         existing_nic_id2)
        self.assertEqual(vm.network_profile.network_interfaces[2].id,
                         new_nic_id)
        self.assertFalse(vm.network_profile.network_interfaces[0].primary)
        self.assertTrue(vm.network_profile.network_interfaces[1].primary)
        self.assertFalse(vm.network_profile.network_interfaces[2].primary)