Merge "Make TestSwiftBasicOps use object_client"
diff --git a/tempest/scenario/test_security_groups_basic_ops.py b/tempest/scenario/test_security_groups_basic_ops.py
index 5e2a9d0..de6b0f9 100644
--- a/tempest/scenario/test_security_groups_basic_ops.py
+++ b/tempest/scenario/test_security_groups_basic_ops.py
@@ -72,6 +72,10 @@
             * test that reverse traffic is still blocked
             * test than revesre traffic is enabled once an appropriate rule has
             been created on source tenant
+        7._test_port_update_new_security_group:
+           * test that traffic is blocked with default security group
+           * test that traffic is enabled after updating port with new security
+           group having appropriate rule
 
     assumptions:
         1. alt_tenant/user existed and is different from primary_tenant/user
@@ -452,7 +456,57 @@
             # in-tenant check
             self._test_in_tenant_block(self.primary_tenant)
             self._test_in_tenant_allow(self.primary_tenant)
+        except Exception:
+            for tenant in self.tenants.values():
+                self._log_console_output(servers=tenant.servers)
+            raise
 
+    @test.attr(type='smoke')
+    @test.services('compute', 'network')
+    def test_port_update_new_security_group(self):
+        """
+        This test verifies the traffic after updating the vm port with new
+        security group having appropiate rule.
+        """
+        new_tenant = self.primary_tenant
+
+        # Create empty security group and add icmp rule in it
+        new_sg = self._create_empty_security_group(
+            namestart='secgroup_new-',
+            tenant_id=new_tenant.creds.tenant_id,
+            client=new_tenant.manager.network_client)
+        icmp_rule = dict(
+            protocol='icmp',
+            direction='ingress',
+        )
+        self._create_security_group_rule(
+            secgroup=new_sg,
+            client=new_tenant.manager.network_client,
+            **icmp_rule)
+        new_tenant.security_groups.update(new_sg=new_sg)
+
+        # Create server with default security group
+        name = 'server-{tenant}-gen-1-'.format(
+               tenant=new_tenant.creds.tenant_name
+        )
+        name = data_utils.rand_name(name)
+        server = self._create_server(name, new_tenant)
+
+        # Check connectivity failure with default security group
+        try:
+            access_point_ssh = self._connect_to_access_point(new_tenant)
+            self._check_connectivity(access_point=access_point_ssh,
+                                     ip=self._get_server_ip(server),
+                                     should_succeed=False)
+            server_id = server['id']
+            port_id = self._list_ports(device_id=server_id)[0]['id']
+
+            # update port with new security group and check connectivity
+            self.network_client.update_port(port_id, security_groups=[
+                new_tenant.security_groups['new_sg'].id])
+            self._check_connectivity(
+                access_point=access_point_ssh,
+                ip=self._get_server_ip(server))
         except Exception:
             for tenant in self.tenants.values():
                 self._log_console_output(servers=tenant.servers)
diff --git a/tempest/tests/test_negative_rest_client.py b/tempest/tests/test_negative_rest_client.py
new file mode 100644
index 0000000..ce95739
--- /dev/null
+++ b/tempest/tests/test_negative_rest_client.py
@@ -0,0 +1,91 @@
+# (c) 2015 Deutsche Telekom AG
+# Copyright 2015 Red Hat, Inc.
+# Copyright 2015 NEC Corporation
+# 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 httplib2
+from oslotest import mockpatch
+
+from tempest.common import negative_rest_client
+from tempest import config
+from tempest.tests import base
+from tempest.tests import fake_auth_provider
+from tempest.tests import fake_config
+from tempest.tests import fake_http
+
+
+class TestNegativeRestClient(base.TestCase):
+
+    url = 'fake_endpoint'
+
+    def setUp(self):
+        self.fake_http = fake_http.fake_httplib2()
+        super(TestNegativeRestClient, self).setUp()
+        self.useFixture(fake_config.ConfigFixture())
+        self.stubs.Set(config, 'TempestConfigPrivate', fake_config.FakePrivate)
+        self.stubs.Set(httplib2.Http, 'request', self.fake_http.request)
+        self.negative_rest_client = negative_rest_client.NegativeRestClient(
+            fake_auth_provider.FakeAuthProvider(), None)
+        self.useFixture(mockpatch.PatchObject(self.negative_rest_client,
+                                              '_log_request'))
+
+    def test_post(self):
+        __, return_dict = self.negative_rest_client.send_request('POST',
+                                                                 self.url,
+                                                                 [], {})
+        self.assertEqual('POST', return_dict['method'])
+
+    def test_get(self):
+        __, return_dict = self.negative_rest_client.send_request('GET',
+                                                                 self.url,
+                                                                 [])
+        self.assertEqual('GET', return_dict['method'])
+
+    def test_delete(self):
+        __, return_dict = self.negative_rest_client.send_request('DELETE',
+                                                                 self.url,
+                                                                 [])
+        self.assertEqual('DELETE', return_dict['method'])
+
+    def test_patch(self):
+        __, return_dict = self.negative_rest_client.send_request('PATCH',
+                                                                 self.url,
+                                                                 [], {})
+        self.assertEqual('PATCH', return_dict['method'])
+
+    def test_put(self):
+        __, return_dict = self.negative_rest_client.send_request('PUT',
+                                                                 self.url,
+                                                                 [], {})
+        self.assertEqual('PUT', return_dict['method'])
+
+    def test_head(self):
+        self.useFixture(mockpatch.PatchObject(self.negative_rest_client,
+                                              'response_checker'))
+        __, return_dict = self.negative_rest_client.send_request('HEAD',
+                                                                 self.url,
+                                                                 [])
+        self.assertEqual('HEAD', return_dict['method'])
+
+    def test_copy(self):
+        __, return_dict = self.negative_rest_client.send_request('COPY',
+                                                                 self.url,
+                                                                 [])
+        self.assertEqual('COPY', return_dict['method'])
+
+    def test_other(self):
+        self.assertRaises(AssertionError,
+                          self.negative_rest_client.send_request,
+                          'OTHER', self.url, [])
diff --git a/tempest/tests/test_rest_client.py b/tempest/tests/test_rest_client.py
index a133800..e42fab7 100644
--- a/tempest/tests/test_rest_client.py
+++ b/tempest/tests/test_rest_client.py
@@ -17,7 +17,6 @@
 import httplib2
 from oslotest import mockpatch
 
-from tempest.common import negative_rest_client
 from tempest.common import rest_client
 from tempest import config
 from tempest import exceptions
@@ -429,66 +428,6 @@
                           '1234')
 
 
-class TestNegativeRestClient(BaseRestClientTestClass):
-
-    def setUp(self):
-        self.fake_http = fake_http.fake_httplib2()
-        super(TestNegativeRestClient, self).setUp()
-        self.negative_rest_client = negative_rest_client.NegativeRestClient(
-            fake_auth_provider.FakeAuthProvider(), None)
-        self.useFixture(mockpatch.PatchObject(self.negative_rest_client,
-                                              '_log_request'))
-
-    def test_post(self):
-        __, return_dict = self.negative_rest_client.send_request('POST',
-                                                                 self.url,
-                                                                 [], {})
-        self.assertEqual('POST', return_dict['method'])
-
-    def test_get(self):
-        __, return_dict = self.negative_rest_client.send_request('GET',
-                                                                 self.url,
-                                                                 [])
-        self.assertEqual('GET', return_dict['method'])
-
-    def test_delete(self):
-        __, return_dict = self.negative_rest_client.send_request('DELETE',
-                                                                 self.url,
-                                                                 [])
-        self.assertEqual('DELETE', return_dict['method'])
-
-    def test_patch(self):
-        __, return_dict = self.negative_rest_client.send_request('PATCH',
-                                                                 self.url,
-                                                                 [], {})
-        self.assertEqual('PATCH', return_dict['method'])
-
-    def test_put(self):
-        __, return_dict = self.negative_rest_client.send_request('PUT',
-                                                                 self.url,
-                                                                 [], {})
-        self.assertEqual('PUT', return_dict['method'])
-
-    def test_head(self):
-        self.useFixture(mockpatch.PatchObject(self.negative_rest_client,
-                                              'response_checker'))
-        __, return_dict = self.negative_rest_client.send_request('HEAD',
-                                                                 self.url,
-                                                                 [])
-        self.assertEqual('HEAD', return_dict['method'])
-
-    def test_copy(self):
-        __, return_dict = self.negative_rest_client.send_request('COPY',
-                                                                 self.url,
-                                                                 [])
-        self.assertEqual('COPY', return_dict['method'])
-
-    def test_other(self):
-        self.assertRaises(AssertionError,
-                          self.negative_rest_client.send_request,
-                          'OTHER', self.url, [])
-
-
 class TestExpectedSuccess(BaseRestClientTestClass):
 
     def setUp(self):