Merge "Fix vif tests"
diff --git a/ironic_tempest_plugin/services/baremetal/v1/json/baremetal_client.py b/ironic_tempest_plugin/services/baremetal/v1/json/baremetal_client.py
index 628a075..5715609 100644
--- a/ironic_tempest_plugin/services/baremetal/v1/json/baremetal_client.py
+++ b/ironic_tempest_plugin/services/baremetal/v1/json/baremetal_client.py
@@ -261,7 +261,12 @@
 
         """
         node = {}
-        for field in ('resource_class', 'name', 'description', 'shard'):
+        # Explicitly allow definition of network interface and deploy
+        # interface to allow tests to specify the required values
+        # as they hold a great deal of logic which is executed upon and
+        # they can ultimately impact test behavior.
+        for field in ('resource_class', 'name', 'description', 'shard',
+                      'network_interface', 'deploy_interface'):
             if kwargs.get(field):
                 node[field] = kwargs[field]
 
@@ -271,7 +276,7 @@
                             'cpus': kwargs.get('cpus', 8),
                             'local_gb': kwargs.get('local_gb', 1024),
                             'memory_mb': kwargs.get('memory_mb', 4096)},
-             'driver': kwargs.get('driver', 'fake')}
+             'driver': kwargs.get('driver', 'fake-hardware')}
         )
 
         return self._create_request('nodes', node)
diff --git a/ironic_tempest_plugin/tests/api/admin/test_nodes.py b/ironic_tempest_plugin/tests/api/admin/test_nodes.py
index c3408ec..79e8da4 100644
--- a/ironic_tempest_plugin/tests/api/admin/test_nodes.py
+++ b/ironic_tempest_plugin/tests/api/admin/test_nodes.py
@@ -312,7 +312,10 @@
         super(TestNodesVif, self).setUp()
 
         _, self.chassis = self.create_chassis()
-        _, self.node = self.create_node(self.chassis['uuid'])
+        # The tests will mostly fail in this class if exposed to the
+        # noop network interface, which is what the default is.
+        _, self.node = self.create_node(self.chassis['uuid'],
+                                        network_interface='flat')
         if CONF.network.shared_physical_network:
             self.net = self.os_admin.networks_client.list_networks(
                 name=CONF.compute.fixed_network_name)['networks'][0]
@@ -432,7 +435,9 @@
                                         data_utils.rand_mac_address())
         self.client.vif_attach(self.node['uuid'], self.nport_id)
         _, body = self.client.vif_list(self.node['uuid'])
+
         self.assertEqual({'vifs': [{'id': self.nport_id}]}, body)
+
         self.assertRaises(lib_exc.Conflict, self.client.vif_attach,
                           self.node['uuid'], self.nport_id)
         self.client.vif_detach(self.node['uuid'], self.nport_id)
@@ -495,6 +500,7 @@
         _, port = self.client.show_port(self.port['uuid'])
         self.assertEqual(self.nport_id,
                          port['internal_info']['tenant_vif_port_id'])
+        self.client.vif_detach(self.node['uuid'], self.nport_id)
 
     @decorators.attr(type='negative')
     @decorators.idempotent_id('85b610cd-5ba8-49a7-8ce2-5e364056fd29')
@@ -545,6 +551,7 @@
                          port['internal_info']['tenant_vif_port_id'])
         _, portgroup = self.client.show_portgroup(self.portgroup['uuid'])
         self.assertNotIn('tenant_vif_port_id', portgroup['internal_info'])
+        self.client.vif_detach(self.node['uuid'], self.nport_id)
 
     @decorators.attr(type='negative')
     @decorators.idempotent_id('3affca81-9f3f-4dab-ad3d-77c892d8d0d7')
@@ -556,20 +563,6 @@
                           self.nport_id)
 
     @decorators.attr(type='negative')
-    @decorators.idempotent_id('9290e1f9-7e75-4e12-aea7-3649348e7f36')
-    def test_vif_attach_no_args(self):
-        """Negative test for VIF attachment with lack of arguments."""
-        self.assertRaises(lib_exc.BadRequest,
-                          self.client.vif_attach,
-                          self.node['uuid'], '')
-        self.assertRaises(lib_exc.BadRequest,
-                          self.client.vif_attach,
-                          '', '')
-        self.assertRaises(lib_exc.BadRequest,
-                          self.client.vif_attach,
-                          '', self.nport_id)
-
-    @decorators.attr(type='negative')
     @decorators.idempotent_id('da036225-47b0-43b7-9586-0d6390bd3cd9')
     def test_vif_detach_not_existing(self):
         """Negative test for VIF detachment of not existing VIF."""
@@ -1119,9 +1112,7 @@
     def setUp(self):
         super(TestNodesProtectedOldApi, self).setUp()
         _, self.chassis = self.create_chassis()
-        _, self.node = self.create_node(self.chassis['uuid'],
-                                        deploy_interface='fake',
-                                        network_interface='noop')
+        _, self.node = self.create_node(self.chassis['uuid'])
         self.deploy_node(self.node['uuid'])
         _, self.node = self.client.show_node(self.node['uuid'])
 
diff --git a/ironic_tempest_plugin/tests/api/admin/test_nodestates.py b/ironic_tempest_plugin/tests/api/admin/test_nodestates.py
index d03a876..010e45b 100644
--- a/ironic_tempest_plugin/tests/api/admin/test_nodestates.py
+++ b/ironic_tempest_plugin/tests/api/admin/test_nodestates.py
@@ -78,9 +78,7 @@
 
     @decorators.idempotent_id('ccb8fca9-2ba0-480c-a037-34c3bd09dc74')
     def test_set_node_provision_state(self):
-        _, node = self.create_node(self.chassis['uuid'],
-                                   deploy_interface='fake',
-                                   network_interface='noop')
+        _, node = self.create_node(self.chassis['uuid'])
         # Nodes appear in NONE state by default until v1.1
         self.assertIsNone(node['provision_state'])
         provision_states_list = ['active', 'deleted']
@@ -96,19 +94,33 @@
     def setUp(self):
         super(TestNodeStatesV1_2, self).setUp()
         self.useFixture(api_microversion_fixture.APIMicroversionFixture('1.2'))
+        # Make node with 1.2, so the start state written to the DB as expected.
+        _, self.node = self.create_node(self.chassis['uuid'])
+        self.useFixture(
+            api_microversion_fixture.APIMicroversionFixture('1.31'))
+        # Now with a 1.31 microversion, swap the deploy and network
+        # interfaces into place so the test doesn't break depending on
+        # the environment's default state.
+        self.client.update_node(self.node['uuid'],
+                                [{'path': '/deploy_interface',
+                                  'op': 'replace',
+                                  'value': 'fake'},
+                                 {'path': '/network_interface',
+                                  'op': 'replace',
+                                  'value': 'noop'}])
+        self.useFixture(api_microversion_fixture.APIMicroversionFixture('1.2'))
 
     @decorators.idempotent_id('9c414984-f3b6-4b3d-81da-93b60d4662fb')
     def test_set_node_provision_state(self):
-        _, node = self.create_node(self.chassis['uuid'],
-                                   deploy_interface='fake',
-                                   network_interface='noop')
+        _, node = self.client.show_node(self.node['uuid'])
         # Nodes appear in AVAILABLE state by default from v1.2 to v1.10
-        self.assertEqual('available', node['provision_state'])
+        self.assertEqual('available', self.node['provision_state'])
         provision_states_list = ['active', 'deleted']
         target_states_list = ['active', 'available']
         for (provision_state, target_state) in zip(provision_states_list,
                                                    target_states_list):
-            self.client.set_node_provision_state(node['uuid'], provision_state)
+            self.client.set_node_provision_state(node['uuid'],
+                                                 provision_state)
             self._validate_provision_state(node['uuid'], target_state)
 
 
@@ -117,12 +129,25 @@
     def setUp(self):
         super(TestNodeStatesV1_4, self).setUp()
         self.useFixture(api_microversion_fixture.APIMicroversionFixture('1.4'))
+        _, self.node = self.create_node(self.chassis['uuid'])
+        self.useFixture(
+            api_microversion_fixture.APIMicroversionFixture('1.31'))
+        # Now with a 1.31 microversion, swap the deploy and network
+        # interfaces into place so the test doesn't break depending on
+        # the environment's default state.
+        self.client.update_node(self.node['uuid'],
+                                [{'path': '/deploy_interface',
+                                  'op': 'replace',
+                                  'value': 'fake'},
+                                 {'path': '/network_interface',
+                                  'op': 'replace',
+                                  'value': 'noop'}])
+        self.useFixture(api_microversion_fixture.APIMicroversionFixture('1.4'))
 
     @decorators.idempotent_id('3d606003-05ce-4b5a-964d-bdee382fafe9')
     def test_set_node_provision_state(self):
-        _, node = self.create_node(self.chassis['uuid'],
-                                   deploy_interface='fake',
-                                   network_interface='noop')
+        # Make node with 1.2, so the start state written to the DB as expected.
+        _, node = self.client.show_node(self.node['uuid'])
         # Nodes appear in AVAILABLE state by default from v1.2 to v1.10
         self.assertEqual('available', node['provision_state'])
         # MANAGEABLE state and PROVIDE transition have been added in v1.4
@@ -132,7 +157,8 @@
             'manageable', 'available', 'active', 'available']
         for (provision_state, target_state) in zip(provision_states_list,
                                                    target_states_list):
-            self.client.set_node_provision_state(node['uuid'], provision_state)
+            self.client.set_node_provision_state(node['uuid'],
+                                                 provision_state)
             self._validate_provision_state(node['uuid'], target_state)
 
 
@@ -140,13 +166,27 @@
 
     def setUp(self):
         super(TestNodeStatesV1_6, self).setUp()
+        # Creates a node with 1.31, and is later reset for the rest of the test
+        # due to Ironic's evolution of drivers.
+        self.useFixture(api_microversion_fixture.APIMicroversionFixture('1.6'))
+        _, self.node = self.create_node(self.chassis['uuid'])
+        self.useFixture(
+            api_microversion_fixture.APIMicroversionFixture('1.31'))
+        # Now with a 1.31 microversion, swap the deploy and network
+        # interfaces into place so the test doesn't break depending on
+        # the environment's default state.
+        self.client.update_node(self.node['uuid'],
+                                [{'path': '/deploy_interface',
+                                  'op': 'replace',
+                                  'value': 'fake'},
+                                 {'path': '/network_interface',
+                                  'op': 'replace',
+                                  'value': 'noop'}])
         self.useFixture(api_microversion_fixture.APIMicroversionFixture('1.6'))
 
     @decorators.idempotent_id('6c9ce4a3-713b-4c76-91af-18c48d01f1bb')
     def test_set_node_provision_state(self):
-        _, node = self.create_node(self.chassis['uuid'],
-                                   deploy_interface='fake',
-                                   network_interface='noop')
+        _, node = self.client.show_node(self.node['uuid'])
         # Nodes appear in AVAILABLE state by default from v1.2 to v1.10
         self.assertEqual('available', node['provision_state'])
         # INSPECT* states have been added in v1.6
@@ -156,33 +196,41 @@
             'manageable', 'manageable', 'available', 'active', 'available']
         for (provision_state, target_state) in zip(provision_states_list,
                                                    target_states_list):
-            self.client.set_node_provision_state(node['uuid'], provision_state)
-            self._validate_provision_state(node['uuid'], target_state)
+            self.client.set_node_provision_state(node['uuid'],
+                                                 provision_state)
+            self._validate_provision_state(node['uuid'],
+                                           target_state)
 
 
 class TestNodeStatesV1_11(TestNodeStatesMixin, base.BaseBaremetalTest):
 
     def setUp(self):
         super(TestNodeStatesV1_11, self).setUp()
+        # Creates a node with 1.31, and is later reset for the rest of the test
+        # due to Ironic's evolution of drivers.
+        self.useFixture(
+            api_microversion_fixture.APIMicroversionFixture('1.31'))
+        _, self.node = self.create_node(self.chassis['uuid'],
+                                        deploy_interface='fake',
+                                        network_interface='noop')
         self.useFixture(
             api_microversion_fixture.APIMicroversionFixture('1.11')
         )
 
     @decorators.idempotent_id('31f53828-b83d-40c7-98e5-843e28a1b6b9')
     def test_set_node_provision_state(self):
-        _, node = self.create_node(self.chassis['uuid'],
-                                   deploy_interface='fake',
-                                   network_interface='noop')
         # Nodes appear in ENROLL state by default from v1.11
-        self.assertEqual('enroll', node['provision_state'])
+        self.assertEqual('enroll', self.node['provision_state'])
         provision_states_list = [
             'manage', 'inspect', 'provide', 'active', 'deleted']
         target_states_list = [
             'manageable', 'manageable', 'available', 'active', 'available']
         for (provision_state, target_state) in zip(provision_states_list,
                                                    target_states_list):
-            self.client.set_node_provision_state(node['uuid'], provision_state)
-            self._validate_provision_state(node['uuid'], target_state)
+            self.client.set_node_provision_state(self.node['uuid'],
+                                                 provision_state)
+            self._validate_provision_state(self.node['uuid'],
+                                           target_state)
 
 
 class TestNodeStatesV1_12(TestNodeStatesMixin, base.BaseBaremetalTest):
diff --git a/ironic_tempest_plugin/tests/api/admin/test_ports.py b/ironic_tempest_plugin/tests/api/admin/test_ports.py
index 9988279..dfb371c 100644
--- a/ironic_tempest_plugin/tests/api/admin/test_ports.py
+++ b/ironic_tempest_plugin/tests/api/admin/test_ports.py
@@ -25,8 +25,7 @@
         super(TestPorts, self).setUp()
 
         _, self.chassis = self.create_chassis()
-        _, self.node = self.create_node(self.chassis['uuid'],
-                                        network_interface='noop')
+        _, self.node = self.create_node(self.chassis['uuid'])
         _, self.port = self.create_port(self.node['uuid'],
                                         data_utils.rand_mac_address())
 
diff --git a/ironic_tempest_plugin/tests/api/admin/test_ports_negative.py b/ironic_tempest_plugin/tests/api/admin/test_ports_negative.py
index 8923aa3..bd338f9 100644
--- a/ironic_tempest_plugin/tests/api/admin/test_ports_negative.py
+++ b/ironic_tempest_plugin/tests/api/admin/test_ports_negative.py
@@ -25,8 +25,7 @@
         super(TestPortsNegative, self).setUp()
 
         _, self.chassis = self.create_chassis()
-        _, self.node = self.create_node(self.chassis['uuid'],
-                                        network_interface='noop')
+        _, self.node = self.create_node(self.chassis['uuid'])
 
     @decorators.attr(type=['negative'])
     @decorators.idempotent_id('0a6ee1f7-d0d9-4069-8778-37f3aa07303a')