Test BM with VM on the same network

L2 isolation and L3 connectivity between: BM and VM
This test will be skipped if Nova is not running.

Change-Id: I89e84140ceae01eb672ae72b1b10e53ff527e172
diff --git a/ironic_tempest_plugin/tests/scenario/test_baremetal_multitenancy.py b/ironic_tempest_plugin/tests/scenario/test_baremetal_multitenancy.py
index f12dc93..92f41fd 100644
--- a/ironic_tempest_plugin/tests/scenario/test_baremetal_multitenancy.py
+++ b/ironic_tempest_plugin/tests/scenario/test_baremetal_multitenancy.py
@@ -26,7 +26,7 @@
 
 class BaremetalMultitenancy(baremetal_manager.BaremetalScenarioTest,
                             manager.NetworkScenarioTest):
-    """Check L2 isolation of baremetal instances in different tenants:
+    """Check L2 isolation of baremetal and VM instances in different tenants:
 
     * Create a keypair, network, subnet and router for the primary tenant
     * Boot 2 instances in the different tenant's network using the keypair
@@ -70,7 +70,6 @@
         self.addCleanup(clients.subnets_client.delete_subnet, subnet['id'])
         self.addCleanup(clients.routers_client.remove_router_interface,
                         router['id'], subnet_id=subnet['id'])
-
         return network, subnet, router
 
     def verify_l3_connectivity(self, source_ip, private_key,
@@ -86,17 +85,15 @@
         else:
             self.assertNotIn(success_substring, output)
 
-    @decorators.idempotent_id('26e2f145-2a8e-4dc7-8457-7f2eb2c6749d')
-    @utils.services('compute', 'image', 'network')
-    def test_baremetal_multitenancy(self):
-
+    def multitenancy_check(self, use_vm=False):
         tenant_cidr = '10.0.100.0/24'
         keypair = self.create_keypair()
         network, subnet, router = self.create_tenant_network(
             self.os_primary, tenant_cidr)
-
-        # Boot 2 instances in the primary tenant network
-        # and check L2 connectivity between them
+        alt_keypair = self.create_keypair(self.os_alt.keypairs_client)
+        alt_network, alt_subnet, alt_router = self.create_tenant_network(
+            self.os_alt, tenant_cidr)
+        # Create single BM guest as Primary
         instance1, node1 = self.boot_instance(
             clients=self.os_primary,
             keypair=keypair,
@@ -108,49 +105,61 @@
         )['floating_ip_address']
         self.check_vm_connectivity(ip_address=floating_ip1,
                                    private_key=keypair['private_key'])
-
-        # Boot instance in the alt tenant network and ensure there is no
-        # L2 connectivity between instances of the different tenants
-        alt_keypair = self.create_keypair(self.os_alt.keypairs_client)
-        alt_network, alt_subnet, alt_router = self.create_tenant_network(
-            self.os_alt, tenant_cidr)
-
-        alt_instance, alt_node = self.boot_instance(
-            keypair=alt_keypair,
-            clients=self.os_alt,
-            net_id=alt_network['id'],
-        )
+        if use_vm:
+            # Create VM on compute node
+            alt_instance = self.create_server(
+                clients=self.os_alt,
+                key_name=alt_keypair['name'],
+                flavor=CONF.compute.flavor_ref_alt,
+                networks=[{'uuid': alt_network['id']}]
+            )
+        else:
+            # Create BM
+            alt_instance, alt_node = self.boot_instance(
+                keypair=alt_keypair,
+                clients=self.os_alt,
+                net_id=alt_network['id'],
+            )
         fixed_ip2 = alt_instance['addresses'][alt_network['name']][0]['addr']
         alt_floating_ip = self.create_floating_ip(
             alt_instance,
             client=self.os_alt.floating_ips_client
         )['floating_ip_address']
-
-        self.check_vm_connectivity(ip_address=alt_floating_ip,
-                                   private_key=alt_keypair['private_key'])
-
+        self.check_vm_connectivity(
+            ip_address=alt_floating_ip,
+            private_key=alt_keypair['private_key'])
         self.verify_l3_connectivity(
             alt_floating_ip,
             alt_keypair['private_key'],
             fixed_ip1,
             conn_expected=False
         )
-
         self.verify_l3_connectivity(
             floating_ip1,
             keypair['private_key'],
             fixed_ip2,
             conn_expected=False
         )
-
         self.verify_l3_connectivity(
             floating_ip1,
             keypair['private_key'],
             alt_floating_ip,
             conn_expected=True
         )
-
         self.terminate_instance(
             instance=alt_instance,
             servers_client=self.os_alt.servers_client)
         self.terminate_instance(instance=instance1)
+
+    @decorators.idempotent_id('26e2f145-2a8e-4dc7-8457-7f2eb2c6749d')
+    @utils.services('compute', 'image', 'network')
+    def test_baremetal_multitenancy(self):
+        self.multitenancy_check()
+
+    @decorators.idempotent_id('9e38631a-2df2-11e9-810e-8c16450ea513')
+    @utils.services('compute', 'image', 'network')
+    def test_baremetal_vm_multitenancy(self):
+        if not CONF.service_available.nova:
+            self.skipTest('Compute service Nova is disabled,'
+                          ' VM is required to run this test')
+        self.multitenancy_check(use_vm=True)