示例#1
0
    def test_plug_vifs_diff_host_except(self, mock_vm_get, mock_plug):
        """Tests that crt vif handles bad inst.host value.

        This test ensures that if we get a timeout exception we still reset
        the inst.host value back to the original value
        """
        inst = powervm.TEST_INST1

        # Set this up as a different host from the inst.host
        self.flags(host='host2')

        # Mock up the CNA response.  Only doing one for simplicity
        mock_vm_get.return_value = [cna('AABBCCDDEE11')]

        # Mock up the network info.
        net_info = [{'address': 'aa:bb:cc:dd:ee:ff', 'vnic_type': 'normal'}]

        # Ensure that an exception is raised by a timeout.
        mock_plug.side_effect = eventlet.timeout.Timeout()

        # Run method
        p_vifs = tf_net.PlugVifs(mock.MagicMock(), self.apt, inst, net_info,
                                 'host_uuid', 'slot_mgr')
        with mock.patch.object(inst, 'save') as mock_inst_save:
            self.assertRaises(exception.VirtualInterfaceCreateException,
                              p_vifs.execute, self.mock_lpar_wrap)

        # The create should have only been called once.
        self.assertEqual(1, mock_plug.call_count)
        # Should have called save to save the new host and then changed it back
        self.assertEqual(2, mock_inst_save.call_count)
        self.assertEqual('host1', inst.host)
示例#2
0
    def test_plug_vifs_rmc_no_create(self, mock_vm_get, mock_vm_crt):
        """Verifies if no creates are needed, none are done."""
        inst = objects.Instance(**powervm.TEST_INSTANCE)

        # Mock up the CNA response.  Both should already exist.
        mock_vm_get.return_value = [cna('AABBCCDDEEFF'), cna('AABBCCDDEE11')]

        # 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:11'}
        ]

        # Run method
        p_vifs = tf_net.PlugVifs(mock.MagicMock(), self.apt, inst, net_info,
                                 'host_uuid')
        resp = p_vifs.execute(self.mock_lpar_wrap)

        # The create should not have been called.  The response should have
        # been empty.
        self.assertEqual(0, mock_vm_crt.call_count)
        self.assertEqual([], resp)

        # State check shouldn't have even been invoked as no creates were
        # required
        self.assertEqual(0, self.mock_lpar_wrap.can_modify_io.call_count)
示例#3
0
    def test_plug_vifs_rmc_no_create(self, mock_vm_get, mock_plug):
        """Verifies if no creates are needed, none are done."""
        inst = objects.Instance(**powervm.TEST_INSTANCE)

        # Mock up the CNA response.  Both should already exist.
        mock_vm_get.return_value = [cna('AABBCCDDEEFF'), cna('AABBCCDDEE11')]

        # Mock up the network info.  This also validates that they will be
        # sanitized to upper case.  This also validates that we don't call
        # get_vnics if no nets have vnic_type 'direct'.
        net_info = [{
            'address': 'aa:bb:cc:dd:ee:ff',
            'vnic_type': 'normal'
        }, {
            'address': 'aa:bb:cc:dd:ee:11',
            'vnic_type': 'normal'
        }]

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

        # The create should have been called with new_vif as False.
        mock_plug.assert_called_with(self.apt,
                                     'host_uuid',
                                     inst,
                                     net_info[1],
                                     'slot_mgr',
                                     new_vif=False)
示例#4
0
    def test_plug_vifs_revert(self, mock_vm_get, mock_plug, mock_unplug):
        """Tests that the revert flow works properly."""
        inst = objects.Instance(**powervm.TEST_INSTANCE)

        # Fake CNA list.  The one pre-existing VIF should *not* get reverted.
        cna_list = [cna('AABBCCDDEEFF'), cna('FFEEDDCCBBAA')]
        mock_vm_get.return_value = cna_list

        # Mock up the network info.  Three roll backs.
        net_info = [{
            'address': 'aa:bb:cc:dd:ee:ff',
            'vnic_type': 'normal'
        }, {
            'address': 'aa:bb:cc:dd:ee:22',
            'vnic_type': 'normal'
        }, {
            'address': 'aa:bb:cc:dd:ee:33',
            'vnic_type': 'normal'
        }]

        # Make sure we test raising an exception
        mock_unplug.side_effect = [exception.NovaException(), None]

        # Run method
        p_vifs = tf_net.PlugVifs(mock.MagicMock(), self.apt, inst, net_info,
                                 'host_uuid', 'slot_mgr')
        p_vifs.execute(self.mock_lpar_wrap)
        p_vifs.revert(self.mock_lpar_wrap, mock.Mock(), mock.Mock())

        # The unplug should be called twice.  The exception shouldn't stop the
        # second call.
        self.assertEqual(2, mock_unplug.call_count)

        # Make sure each call is invoked correctly.  The first plug was not a
        # new vif, so it should not be reverted.
        c2 = mock.call(self.apt,
                       'host_uuid',
                       inst,
                       net_info[1],
                       'slot_mgr',
                       cna_w_list=cna_list)
        c3 = mock.call(self.apt,
                       'host_uuid',
                       inst,
                       net_info[2],
                       'slot_mgr',
                       cna_w_list=cna_list)
        mock_unplug.assert_has_calls([c2, c3])
示例#5
0
    def test_get_vif_events(self):
        # Set up common mocks.
        inst = objects.Instance(**powervm.TEST_INSTANCE)
        net_info = [mock.MagicMock(), mock.MagicMock()]
        net_info[0]['id'] = 'a'
        net_info[0].get.return_value = False
        net_info[1]['id'] = 'b'
        net_info[1].get.return_value = True

        # Set up the runner.
        p_vifs = tf_net.PlugVifs(mock.MagicMock(), self.apt, inst, net_info,
                                 'host_uuid', 'slot_mgr')
        p_vifs.crt_network_infos = net_info

        resp = p_vifs._get_vif_events()

        # Only one should be returned since only one was active.
        self.assertEqual(1, len(resp))
示例#6
0
    def test_plug_vifs_invalid_state(self, mock_vm_get, mock_plug):
        """Tests that a crt_vif fails when the LPAR state is bad."""
        inst = objects.Instance(**powervm.TEST_INSTANCE)

        # Mock up the CNA response.  Only doing one for simplicity
        mock_vm_get.return_value = []
        net_info = [{'address': 'aa:bb:cc:dd:ee:ff', 'vnic_type': 'normal'}]

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

        # Run method
        p_vifs = tf_net.PlugVifs(mock.MagicMock(), self.apt, inst, net_info,
                                 'host_uuid', 'slot_mgr')
        self.assertRaises(exception.VirtualInterfaceCreateException,
                          p_vifs.execute, self.mock_lpar_wrap)

        # The create should not have been invoked
        self.assertEqual(0, mock_plug.call_count)
示例#7
0
    def test_plug_vifs_timeout(self, mock_vm_get, mock_plug):
        """Tests that crt vif failure via loss of neutron callback."""
        inst = objects.Instance(**powervm.TEST_INSTANCE)

        # Mock up the CNA response.  Only doing one for simplicity
        mock_vm_get.return_value = [cna('AABBCCDDEE11')]

        # Mock up the network info.
        net_info = [{'address': 'aa:bb:cc:dd:ee:ff', 'vnic_type': 'normal'}]

        # Ensure that an exception is raised by a timeout.
        mock_plug.side_effect = eventlet.timeout.Timeout()

        # Run method
        p_vifs = tf_net.PlugVifs(mock.MagicMock(), self.apt, inst, net_info,
                                 'host_uuid', 'slot_mgr')
        self.assertRaises(exception.VirtualInterfaceCreateException,
                          p_vifs.execute, self.mock_lpar_wrap)

        # The create should have only been called once.
        self.assertEqual(1, mock_plug.call_count)
示例#8
0
    def test_plug_vifs_rmc(self, mock_vm_get, mock_vm_crt):
        """Tests that a crt vif can be done with secure RMC."""
        inst = objects.Instance(**powervm.TEST_INSTANCE)

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

        # 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.PlugVifs(mock.MagicMock(), self.apt, inst, net_info,
                                 'host_uuid')
        p_vifs.execute(self.mock_lpar_wrap)

        # The create should have only been called once.
        self.assertEqual(2, mock_vm_crt.call_count)
示例#9
0
    def test_get_vif_events(self, mock_is_neutron):
        # Set up common mocks.
        inst = objects.Instance(**powervm.TEST_INSTANCE)
        net_info = [mock.MagicMock(), mock.MagicMock()]
        net_info[0]['id'] = 'a'
        net_info[0].get.return_value = False
        net_info[1]['id'] = 'b'
        net_info[1].get.return_value = True

        # Set up the runner.
        p_vifs = tf_net.PlugVifs(mock.MagicMock(), self.apt, inst, net_info,
                                 'host_uuid')

        # Mock that neutron is off.
        mock_is_neutron.return_value = False
        self.assertEqual([], p_vifs._get_vif_events())

        # Turn neutron on.
        mock_is_neutron.return_value = True
        resp = p_vifs._get_vif_events()

        # Only one should be returned since only one was active.
        self.assertEqual(1, len(resp))
示例#10
0
    def test_plug_vifs_diff_host(self, mock_vm_get, mock_vm_crt):
        """Tests that crt vif handles bad inst.host value."""
        inst = powervm.TEST_INST1
        # Set this up as a different host from the inst.host
        self.flags(host='host2')

        # Mock up the CNA response.  Only doing one for simplicity
        mock_vm_get.return_value = [cna('AABBCCDDEE11')]

        # Mock up the network info.
        net_info = [{'address': 'aa:bb:cc:dd:ee:ff'}]

        # Run method
        p_vifs = tf_net.PlugVifs(mock.MagicMock(), self.apt, inst, net_info,
                                 'host_uuid')
        with mock.patch.object(inst, 'save') as mock_inst_save:
            p_vifs.execute(self.mock_lpar_wrap)

        # The create should have only been called once.
        self.assertEqual(1, mock_vm_crt.call_count)
        # Should have called save to save the new host and then changed it back
        self.assertEqual(2, mock_inst_save.call_count)
        self.assertEqual('host1', inst.host)
示例#11
0
    def test_plug_vifs_rmc(self, mock_vnic_get, mock_cna_get, mock_plug):
        """Tests that a crt vif can be done with secure RMC."""
        inst = objects.Instance(**powervm.TEST_INSTANCE)

        # Mock up the CNA response.  One should already exist, the other
        # should not.
        pre_cnas = [cna('AABBCCDDEEFF'), cna('AABBCCDDEE11')]
        mock_cna_get.return_value = copy.deepcopy(pre_cnas)
        # Ditto VNIC response.
        mock_vnic_get.return_value = [cna('AABBCCDDEE33'), cna('AABBCCDDEE44')]

        # 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',
            'vnic_type': 'normal'
        }, {
            'address': 'aa:bb:cc:dd:ee:22',
            'vnic_type': 'normal'
        }, {
            'address': 'aa:bb:cc:dd:ee:33',
            'vnic_type': 'direct'
        }, {
            'address': 'aa:bb:cc:dd:ee:55',
            'vnic_type': 'direct'
        }]

        # Both updates run first (one CNA, one VNIC); then the CNA create, then
        # the VNIC create.
        mock_new_cna = mock.Mock(spec=pvm_net.CNA)
        mock_new_vnic = mock.Mock(spec=pvm_card.VNIC)
        mock_plug.side_effect = [
            'upd_cna', 'upd_vnic', mock_new_cna, mock_new_vnic
        ]

        # Run method
        p_vifs = tf_net.PlugVifs(mock.MagicMock(), self.apt, inst, net_info,
                                 'host_uuid', 'slot_mgr')

        all_cnas = p_vifs.execute(self.mock_lpar_wrap)

        # new vif should be created twice.
        mock_plug.assert_any_call(self.apt,
                                  'host_uuid',
                                  inst,
                                  net_info[0],
                                  'slot_mgr',
                                  new_vif=False)
        mock_plug.assert_any_call(self.apt,
                                  'host_uuid',
                                  inst,
                                  net_info[1],
                                  'slot_mgr',
                                  new_vif=True)
        mock_plug.assert_any_call(self.apt,
                                  'host_uuid',
                                  inst,
                                  net_info[2],
                                  'slot_mgr',
                                  new_vif=False)
        mock_plug.assert_any_call(self.apt,
                                  'host_uuid',
                                  inst,
                                  net_info[3],
                                  'slot_mgr',
                                  new_vif=True)

        # The Task provides the list of original CNAs plus only CNAs that were
        # created.
        self.assertEqual(pre_cnas + [mock_new_cna], all_cnas)