Esempio n. 1
0
    def test_unplug_vifs(self, mock_vm_get, mock_unplug):
        """Tests that a delete of the vif can be done."""
        inst = objects.Instance(**powervm.TEST_INSTANCE)

        # Mock up the CNA responses.
        cnas = [cna('AABBCCDDEEFF'), cna('AABBCCDDEE11'), cna('AABBCCDDEE22')]
        mock_vm_get.return_value = cnas

        # Mock up the network info.  This also validates that they will be
        # sanitized to upper case.
        net_info = [{
            'address': 'aa:bb:cc:dd:ee:ff'
        }, {
            'address': 'aa:bb:cc:dd:ee:22'
        }, {
            'address': 'aa:bb:cc:dd:ee:33'
        }]

        # Mock out the vif driver
        def validate_unplug(adapter,
                            host_uuid,
                            instance,
                            vif,
                            slot_mgr,
                            cna_w_list=None):
            self.assertEqual(adapter, self.apt)
            self.assertEqual('host_uuid', host_uuid)
            self.assertEqual(instance, inst)
            self.assertIn(vif, net_info)
            self.assertEqual('slot_mgr', slot_mgr)
            self.assertEqual(cna_w_list, cnas)

        mock_unplug.side_effect = validate_unplug

        # Run method
        p_vifs = tf_net.UnplugVifs(self.apt, inst, net_info, 'host_uuid',
                                   'slot_mgr')
        p_vifs.execute(self.mock_lpar_wrap)

        # Make sure the unplug was invoked, so that we know that the validation
        # code was called
        self.assertEqual(3, mock_unplug.call_count)

        # Validate args on taskflow.task.Task instantiation
        with mock.patch('taskflow.task.Task.__init__') as tf:
            tf_net.UnplugVifs(self.apt, inst, net_info, 'host_uuid',
                              'slot_mgr')
        tf.assert_called_once_with(name='unplug_vifs', requires=['lpar_wrap'])
Esempio n. 2
0
    def test_unplug_vifs(self, mock_vm_get):
        """Tests that a delete of the vif can be done."""
        inst = objects.Instance(**powervm.TEST_INSTANCE)

        # Mock up the CNA response.  One should already exist, the other
        # should not.
        cnas = [cna('AABBCCDDEEFF'), cna('AABBCCDDEE11'), cna('AABBCCDDEE22')]
        mock_vm_get.return_value = cnas

        # Mock up the network info.  This also validates that they will be
        # sanitized to upper case.
        net_info = [
            {'address': 'aa:bb:cc:dd:ee:ff'}, {'address': 'aa:bb:cc:dd:ee:22'},
            {'address': 'aa:bb:cc:dd:ee:33'}
        ]

        # Run method
        p_vifs = tf_net.UnplugVifs(self.apt, inst, net_info, 'host_uuid')
        p_vifs.execute(self.mock_lpar_wrap)

        # The delete should have only been called once.  The second CNA didn't
        # have a matching mac...so it should be skipped.
        self.assertEqual(1, cnas[0].delete.call_count)
        self.assertEqual(0, cnas[1].delete.call_count)
        self.assertEqual(1, cnas[2].delete.call_count)
Esempio n. 3
0
    def test_unplug_vifs_invalid_state(self):
        """Tests that the delete raises an exception if bad VM state."""
        inst = objects.Instance(**powervm.TEST_INSTANCE)

        # Mock that the state is incorrect
        self.mock_lpar_wrap.can_modify_io.return_value = False, 'bad'

        # Run method
        p_vifs = tf_net.UnplugVifs(self.apt, inst, mock.Mock(), 'host_uuid')
        self.assertRaises(tf_net.VirtualInterfaceUnplugException,
                          p_vifs.execute, self.mock_lpar_wrap)