Merge "Enable cinder v2 api tests in volume quotas"
diff --git a/HACKING.rst b/HACKING.rst
index e57b670..e920634 100644
--- a/HACKING.rst
+++ b/HACKING.rst
@@ -8,7 +8,8 @@
 Tempest Specific Commandments
 ------------------------------
 
-- [T102] Cannot import OpenStack python clients in tempest/api tests
+- [T102] Cannot import OpenStack python clients in tempest/api &
+         tempest/scenario tests
 - [T104] Scenario tests require a services decorator
 - [T105] Unit tests cannot use setUpClass
 - [T106] vim configuration should not be kept in source files.
diff --git a/etc/tempest.conf.sample b/etc/tempest.conf.sample
index 13ee8fe..b70b446 100644
--- a/etc/tempest.conf.sample
+++ b/etc/tempest.conf.sample
@@ -467,9 +467,6 @@
 # [nova.vnc]->vnc_enabled in nova.conf (boolean value)
 #vnc_console = false
 
-# If false skip all v2 api tests with xml (boolean value)
-#xml_api_v2 = true
-
 
 [dashboard]
 
@@ -632,9 +629,6 @@
 # (boolean value)
 #trust = true
 
-# If false, skip all identity api tests with xml (boolean value)
-#xml_api = false
-
 
 [image]
 
@@ -810,9 +804,6 @@
 # attributes ipv6_ra_mode and ipv6_address_mode (boolean value)
 #ipv6_subnet_attributes = false
 
-# If false, skip all network api tests with xml (boolean value)
-#xml_api = false
-
 
 [object-storage]
 
diff --git a/tempest/README.rst b/tempest/README.rst
index fb25151..d28c3f9 100644
--- a/tempest/README.rst
+++ b/tempest/README.rst
@@ -55,7 +55,8 @@
 functionality. They are typically a series of steps where complicated
 state requiring multiple services is set up exercised, and torn down.
 
-Scenario tests can and should use the OpenStack python clients.
+Scenario tests should not use the existing python clients for OpenStack,
+but should instead use the tempest implementations of clients.
 
 
 :ref:`stress_field_guide`
diff --git a/tempest/api/compute/base.py b/tempest/api/compute/base.py
index 2f53a0b..6a3ee44 100644
--- a/tempest/api/compute/base.py
+++ b/tempest/api/compute/base.py
@@ -38,9 +38,6 @@
     def resource_setup(cls):
         cls.set_network_resources()
         super(BaseComputeTest, cls).resource_setup()
-        if getattr(cls, '_interface', None) == 'xml' and cls._api_version == 2:
-            if not CONF.compute_feature_enabled.xml_api_v2:
-                raise cls.skipException('XML API is not enabled')
 
         # TODO(andreaf) WE should care also for the alt_manager here
         # but only once client lazy load in the manager is done
diff --git a/tempest/api/network/base.py b/tempest/api/network/base.py
index 4b5f107..b13dd22 100644
--- a/tempest/api/network/base.py
+++ b/tempest/api/network/base.py
@@ -62,9 +62,6 @@
         super(BaseNetworkTest, cls).resource_setup()
         if not CONF.service_available.neutron:
             raise cls.skipException("Neutron support is required")
-        if getattr(cls, '_interface', None) == 'xml':
-            if not CONF.network_feature_enabled.xml_api:
-                raise cls.skipException('XML API is not enabled')
         if cls._ip_version == 6 and not CONF.network_feature_enabled.ipv6:
             raise cls.skipException("IPv6 Tests are disabled.")
 
diff --git a/tempest/config.py b/tempest/config.py
index 616a476..b467f83 100644
--- a/tempest/config.py
+++ b/tempest/config.py
@@ -143,9 +143,6 @@
     cfg.BoolOpt('api_v3',
                 default=True,
                 help='Is the v3 identity API enabled'),
-    cfg.BoolOpt('xml_api',
-                default=False,
-                help='If false, skip all identity api tests with xml'),
 ]
 
 compute_group = cfg.OptGroup(name='compute',
@@ -280,9 +277,6 @@
     cfg.BoolOpt('api_v3',
                 default=False,
                 help="If false, skip all nova v3 tests."),
-    cfg.BoolOpt('xml_api_v2',
-                default=True,
-                help="If false skip all v2 api tests with xml"),
     cfg.BoolOpt('disk_config',
                 default=True,
                 help="If false, skip disk config tests"),
@@ -491,9 +485,6 @@
                      "the extended IPv6 attributes ipv6_ra_mode "
                      "and ipv6_address_mode"
                 ),
-    cfg.BoolOpt('xml_api',
-                default=False,
-                help='If false, skip all network api tests with xml')
 ]
 
 messaging_group = cfg.OptGroup(name='messaging',
diff --git a/tempest/hacking/checks.py b/tempest/hacking/checks.py
index 6014cff..29898a9 100644
--- a/tempest/hacking/checks.py
+++ b/tempest/hacking/checks.py
@@ -30,18 +30,18 @@
 mutable_default_args = re.compile(r"^\s*def .+\((.+=\{\}|.+=\[\])")
 
 
-def import_no_clients_in_api(physical_line, filename):
-    """Check for client imports from tempest/api tests
+def import_no_clients_in_api_and_scenario_tests(physical_line, filename):
+    """Check for client imports from tempest/api & tempest/scenario tests
 
     T102: Cannot import OpenStack python clients
     """
 
-    if "tempest/api" in filename:
+    if "tempest/api" in filename or "tempest/scenario" in filename:
         res = PYTHON_CLIENT_RE.match(physical_line)
         if res:
             return (physical_line.find(res.group(1)),
                     ("T102: python clients import not allowed"
-                     " in tempest/api/* tests"))
+                     " in tempest/api/* or tempest/scenario/* tests"))
 
 
 def scenario_tests_need_service_tags(physical_line, filename,
@@ -117,7 +117,7 @@
 
 
 def factory(register):
-    register(import_no_clients_in_api)
+    register(import_no_clients_in_api_and_scenario_tests)
     register(scenario_tests_need_service_tags)
     register(no_setup_teardown_class_for_tests)
     register(no_vi_headers)
diff --git a/tempest/scenario/README.rst b/tempest/scenario/README.rst
index 5a287d6..38e0de9 100644
--- a/tempest/scenario/README.rst
+++ b/tempest/scenario/README.rst
@@ -29,9 +29,9 @@
 
 Scope of these tests
 --------------------
-Scenario tests should use the official python client libraries for
-OpenStack, as they provide a more realistic approach in how people
-will interact with the services.
+Scenario tests should always use the Tempest implementation of the
+OpenStack API, as we want to ensure that bugs aren't hidden by the
+official clients.
 
 Tests should be tagged with which services they exercise, as
 determined by which client libraries are used directly by the test.
diff --git a/tempest/scenario/test_shelve_instance.py b/tempest/scenario/test_shelve_instance.py
new file mode 100644
index 0000000..3ee71dd
--- /dev/null
+++ b/tempest/scenario/test_shelve_instance.py
@@ -0,0 +1,96 @@
+# Copyright 2014 Scality
+# 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.
+
+import testtools
+
+from tempest import config
+from tempest.openstack.common import log
+from tempest.scenario import manager
+from tempest import test
+
+CONF = config.CONF
+
+LOG = log.getLogger(__name__)
+
+
+class TestShelveInstance(manager.ScenarioTest):
+    """
+    This test shelves then unshelves a Nova instance
+    The following is the scenario outline:
+     * boot a instance and create a timestamp file in it
+     * shelve the instance
+     * unshelve the instance
+     * check the existence of the timestamp file in the unshelved instance
+
+    """
+
+    def _write_timestamp(self, server_or_ip):
+        ssh_client = self.get_remote_client(server_or_ip)
+        ssh_client.exec_command('date > /tmp/timestamp; sync')
+        self.timestamp = ssh_client.exec_command('cat /tmp/timestamp')
+
+    def _check_timestamp(self, server_or_ip):
+        ssh_client = self.get_remote_client(server_or_ip)
+        got_timestamp = ssh_client.exec_command('cat /tmp/timestamp')
+        self.assertEqual(self.timestamp, got_timestamp)
+
+    def _shelve_then_unshelve_server(self, server):
+        self.servers_client.shelve_server(server['id'])
+        offload_time = CONF.compute.shelved_offload_time
+        if offload_time >= 0:
+            self.servers_client.wait_for_server_status(
+                server['id'], 'SHELVED_OFFLOADED', extra_timeout=offload_time)
+        else:
+            self.servers_client.wait_for_server_status(server['id'], 'SHELVED')
+            self.servers_client.shelve_offload_server(server['id'])
+            self.servers_client.wait_for_server_status(server['id'],
+                                                       'SHELVED_OFFLOADED')
+        self.servers_client.unshelve_server(server['id'])
+        self.servers_client.wait_for_server_status(server['id'], 'ACTIVE')
+
+    @testtools.skipUnless(CONF.compute_feature_enabled.shelve,
+                          'Shelve is not available.')
+    @test.services('compute', 'network', 'image')
+    def test_shelve_instance(self):
+        self.keypair = self.create_keypair()
+
+        self.security_group = self._create_security_group()
+
+        create_kwargs = {
+            'key_name': self.keypair['name'],
+            'security_groups': [self.security_group]
+        }
+        server = self.create_server(image=CONF.compute.image_ref,
+                                    create_kwargs=create_kwargs)
+
+        if CONF.compute.use_floatingip_for_ssh:
+            _, floating_ip = self.floating_ips_client.create_floating_ip()
+            self.addCleanup(self.delete_wrapper,
+                            self.floating_ips_client.delete_floating_ip,
+                            floating_ip['id'])
+            self.floating_ips_client.associate_floating_ip_to_server(
+                floating_ip['ip'], server['id'])
+            self._write_timestamp(floating_ip['ip'])
+        else:
+            self._write_timestamp(server)
+
+        # Prevent bug #1257594 from coming back
+        # Unshelve used to boot the instance with the original image, not
+        # with the instance snapshot
+        self._shelve_then_unshelve_server(server)
+        if CONF.compute.use_floatingip_for_ssh:
+            self._check_timestamp(floating_ip['ip'])
+        else:
+            self._check_timestamp(server)
diff --git a/tempest/tests/test_hacking.py b/tempest/tests/test_hacking.py
index 6857461..fd01887 100644
--- a/tempest/tests/test_hacking.py
+++ b/tempest/tests/test_hacking.py
@@ -69,13 +69,18 @@
         self.assertFalse(checks.no_setup_teardown_class_for_tests(
             "  def tearDownClass(cls):", './tempest/test.py'))
 
-    def test_import_no_clients_in_api(self):
+    def test_import_no_clients_in_api_and_scenario_tests(self):
         for client in checks.PYTHON_CLIENTS:
             string = "import " + client + "client"
-            self.assertTrue(checks.import_no_clients_in_api(
-                string, './tempest/api/fake_test.py'))
-            self.assertFalse(checks.import_no_clients_in_api(
-                string, './tempest/scenario/fake_test.py'))
+            self.assertTrue(
+                checks.import_no_clients_in_api_and_scenario_tests(
+                    string, './tempest/api/fake_test.py'))
+            self.assertTrue(
+                checks.import_no_clients_in_api_and_scenario_tests(
+                    string, './tempest/scenario/fake_test.py'))
+            self.assertFalse(
+                checks.import_no_clients_in_api_and_scenario_tests(
+                    string, './tempest/test.py'))
 
     def test_scenario_tests_need_service_tags(self):
         self.assertFalse(checks.scenario_tests_need_service_tags(