Migrate negative test to a different file

Here added a different file to store
negative tests of migration.

Partially implements blueprint negative-test-files

Change-Id: I1791265882d0fd748445c39884906983068b5179
diff --git a/tempest/api/compute/test_live_block_migration.py b/tempest/api/compute/test_live_block_migration.py
index fcd055b..1df4159 100644
--- a/tempest/api/compute/test_live_block_migration.py
+++ b/tempest/api/compute/test_live_block_migration.py
@@ -13,14 +13,11 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
-import random
-import string
 
 import testtools
 
 from tempest.api.compute import base
 from tempest import config
-from tempest import exceptions
 from tempest.test import attr
 
 CONF = config.CONF
@@ -65,14 +62,6 @@
             if host != target_host:
                 return target_host
 
-    def _get_non_existing_host_name(self):
-        random_name = ''.join(
-            random.choice(string.ascii_uppercase) for x in range(20))
-
-        self.assertNotIn(random_name, self._get_compute_hostnames())
-
-        return random_name
-
     def _get_server_status(self, server_id):
         return self._get_server_details(server_id)['status']
 
@@ -110,18 +99,6 @@
         self.servers_client.wait_for_server_status(server_id, 'ACTIVE')
         self.assertEqual(target_host, self._get_host_for_server(server_id))
 
-    @testtools.skipIf(not CONF.compute_feature_enabled.live_migration,
-                      'Live migration not available')
-    @attr(type='gate')
-    def test_invalid_host_for_migration(self):
-        # Migrating to an invalid host should not change the status
-        server_id = self._get_an_active_server()
-        target_host = self._get_non_existing_host_name()
-
-        self.assertRaises(exceptions.BadRequest, self._migrate_server_to,
-                          server_id, target_host)
-        self.assertEqual('ACTIVE', self._get_server_status(server_id))
-
     @testtools.skipIf(not CONF.compute_feature_enabled.live_migration or not
                       CONF.compute_feature_enabled.
                       block_migration_for_live_migration,
@@ -155,13 +132,6 @@
         self.servers_client.wait_for_server_status(server_id, 'ACTIVE')
         self.assertEqual(target_host, self._get_host_for_server(server_id))
 
-    @classmethod
-    def tearDownClass(cls):
-        for server_id in cls.created_server_ids:
-            cls.servers_client.delete_server(server_id)
-
-        super(LiveBlockMigrationTestJSON, cls).tearDownClass()
-
 
 class LiveBlockMigrationTestXML(LiveBlockMigrationTestJSON):
     _host_key = (
diff --git a/tempest/api/compute/test_live_block_migration_negative.py b/tempest/api/compute/test_live_block_migration_negative.py
new file mode 100644
index 0000000..da0e4c4
--- /dev/null
+++ b/tempest/api/compute/test_live_block_migration_negative.py
@@ -0,0 +1,60 @@
+# Copyright 2012 OpenStack Foundation
+# All Rights Reserved.
+#
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
+#    not use this file except in compliance with the License. You may obtain
+#    a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+#    License for the specific language governing permissions and limitations
+#    under the License.
+
+
+from tempest.api.compute import base
+from tempest.common.utils import data_utils
+from tempest import config
+from tempest import exceptions
+from tempest import test
+
+CONF = config.CONF
+
+
+class LiveBlockMigrationNegativeTestJSON(base.BaseV2ComputeAdminTest):
+    _host_key = 'OS-EXT-SRV-ATTR:host'
+    _interface = 'json'
+
+    @classmethod
+    def setUpClass(cls):
+        super(LiveBlockMigrationNegativeTestJSON, cls).setUpClass()
+        if not CONF.compute_feature_enabled.live_migration:
+            raise cls.skipException("Live migration is not enabled")
+        cls.admin_hosts_client = cls.os_adm.hosts_client
+        cls.admin_servers_client = cls.os_adm.servers_client
+
+    def _migrate_server_to(self, server_id, dest_host):
+        _resp, body = self.admin_servers_client.live_migrate_server(
+            server_id, dest_host,
+            self.config.compute_feature_enabled.
+            block_migration_for_live_migration)
+        return body
+
+    @test.attr(type=['negative', 'gate'])
+    def test_invalid_host_for_migration(self):
+        # Migrating to an invalid host should not change the status
+        target_host = data_utils.rand_name('host-')
+        _, server = self.create_test_server(wait_until="ACTIVE")
+        server_id = server['id']
+
+        self.assertRaises(exceptions.BadRequest, self._migrate_server_to,
+                          server_id, target_host)
+        self.servers_client.wait_for_server_status(server_id, 'ACTIVE')
+
+
+class LiveBlockMigrationNegativeTestXML(LiveBlockMigrationNegativeTestJSON):
+    _host_key = (
+        '{http://docs.openstack.org/compute/ext/extended_status/api/v1.1}host')
+    _interface = 'xml'
diff --git a/tempest/api/compute/v3/test_live_block_migration.py b/tempest/api/compute/v3/test_live_block_migration.py
index 144cadb..43b4e2b 100644
--- a/tempest/api/compute/v3/test_live_block_migration.py
+++ b/tempest/api/compute/v3/test_live_block_migration.py
@@ -13,14 +13,10 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
-import random
-import string
-
 import testtools
 
 from tempest.api.compute import base
 from tempest import config
-from tempest import exceptions
 from tempest.test import attr
 
 CONF = config.CONF
@@ -66,14 +62,6 @@
             if host != target_host:
                 return target_host
 
-    def _get_non_existing_host_name(self):
-        random_name = ''.join(
-            random.choice(string.ascii_uppercase) for x in range(20))
-
-        self.assertNotIn(random_name, self._get_compute_hostnames())
-
-        return random_name
-
     def _get_server_status(self, server_id):
         return self._get_server_details(server_id)['status']
 
@@ -111,18 +99,6 @@
         self.servers_client.wait_for_server_status(server_id, 'ACTIVE')
         self.assertEqual(target_host, self._get_host_for_server(server_id))
 
-    @testtools.skipIf(not CONF.compute_feature_enabled.live_migration,
-                      'Live migration not available')
-    @attr(type='gate')
-    def test_invalid_host_for_migration(self):
-        # Migrating to an invalid host should not change the status
-        server_id = self._get_an_active_server()
-        target_host = self._get_non_existing_host_name()
-
-        self.assertRaises(exceptions.BadRequest, self._migrate_server_to,
-                          server_id, target_host)
-        self.assertEqual('ACTIVE', self._get_server_status(server_id))
-
     @testtools.skipIf(not CONF.compute_feature_enabled.live_migration or not
                       CONF.compute_feature_enabled.
                       block_migration_for_live_migration,
@@ -155,10 +131,3 @@
         self._migrate_server_to(server_id, target_host)
         self.servers_client.wait_for_server_status(server_id, 'ACTIVE')
         self.assertEqual(target_host, self._get_host_for_server(server_id))
-
-    @classmethod
-    def tearDownClass(cls):
-        for server_id in cls.created_server_ids:
-            cls.servers_client.delete_server(server_id)
-
-        super(LiveBlockMigrationV3Test, cls).tearDownClass()
diff --git a/tempest/api/compute/v3/test_live_block_migration_negative.py b/tempest/api/compute/v3/test_live_block_migration_negative.py
new file mode 100644
index 0000000..4d820d8
--- /dev/null
+++ b/tempest/api/compute/v3/test_live_block_migration_negative.py
@@ -0,0 +1,54 @@
+# Copyright 2012 OpenStack Foundation
+# All Rights Reserved.
+#
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
+#    not use this file except in compliance with the License. You may obtain
+#    a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+#    License for the specific language governing permissions and limitations
+#    under the License.
+
+
+from tempest.api.compute import base
+from tempest.common.utils import data_utils
+from tempest import config
+from tempest import exceptions
+from tempest import test
+
+CONF = config.CONF
+
+
+class LiveBlockMigrationV3NegativeTest(base.BaseV3ComputeAdminTest):
+    _host_key = 'os-extended-server-attributes:host'
+    _interface = 'json'
+
+    @classmethod
+    def setUpClass(cls):
+        super(LiveBlockMigrationV3NegativeTest, cls).setUpClass()
+        if not CONF.compute_feature_enabled.live_migration:
+            raise cls.skipException("Live migration is not enabled")
+
+        cls.admin_hosts_client = cls.hosts_admin_client
+        cls.admin_servers_client = cls.servers_admin_client
+
+    def _migrate_server_to(self, server_id, dest_host):
+        _resp, body = self.admin_servers_client.live_migrate_server(
+            server_id, dest_host,
+            self.config.compute_feature_enabled.
+            block_migration_for_live_migration)
+        return body
+
+    @test.attr(type=['negative', 'gate'])
+    def test_invalid_host_for_migration(self):
+        # Migrating to an invalid host should not change the status
+        target_host = data_utils.rand_name('host-')
+        _, server = self.create_test_server(wait_until="ACTIVE")
+        server_id = server['id']
+        self.assertRaises(exceptions.BadRequest, self._migrate_server_to,
+                          server_id, target_host)
+        self.servers_client.wait_for_server_status(server_id, 'ACTIVE')