]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Completes coverage of quantum.agent.linux.utils
authorZhongyue Luo <zhongyue.nah@intel.com>
Thu, 29 Nov 2012 07:50:12 +0000 (15:50 +0800)
committerZhongyue Luo <zhongyue.nah@intel.com>
Fri, 30 Nov 2012 16:20:38 +0000 (01:20 +0900)
Renamed test_agent_utils to test_agent_linux_utils
Added test cases

Fixes bug #1084817

Change-Id: If0269a003bd8e1fc6f6ef3c622d7a015dadf50aa

quantum/agent/linux/utils.py
quantum/tests/unit/test_agent_linux_utils.py [moved from quantum/tests/unit/test_agent_utils.py with 75% similarity]

index 5a55e0d4d19d4fa6bc8c6dc6471fdbc42b023b91..284864f48c1dba07a58ba55496bef7fe1c1ff386 100644 (file)
@@ -3,17 +3,17 @@
 # Copyright 2012 Locaweb.
 # 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
+#    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
+#         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.
+#    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.
 #
 # @author: Juliano Martinez, Locaweb.
 
@@ -29,6 +29,7 @@ from eventlet.green import subprocess
 from quantum.common import utils
 from quantum.openstack.common import log as logging
 
+
 LOG = logging.getLogger(__name__)
 
 
@@ -70,4 +71,4 @@ def get_interface_mac(interface):
     info = fcntl.ioctl(s.fileno(), 0x8927,
                        struct.pack('256s', interface[:DEVICE_NAME_LEN]))
     return ''.join(['%02x:' % ord(char)
-                   for char in info[MAC_START:MAC_END]])[:-1]
+                    for char in info[MAC_START:MAC_END]])[:-1]
similarity index 75%
rename from quantum/tests/unit/test_agent_utils.py
rename to quantum/tests/unit/test_agent_linux_utils.py
index 73053890a5ae6dcd8b0e704133912f9ecdce6d9c..f7b3a98830b45120779066f0175017e31adad758 100644 (file)
@@ -54,3 +54,19 @@ class AgentUtilsExecuteTest(unittest.TestCase):
         result = utils.execute(["cat"], process_input="%s\n" %
                                self.test_file[:-1])
         self.assertEqual(result, "%s\n" % self.test_file[:-1])
+
+    def test_with_addl_env(self):
+        result = utils.execute(["ls", self.test_file],
+                               addl_env={'foo': 'bar'})
+        self.assertEqual(result, "%s\n" % self.test_file)
+
+
+class AgentUtilsGetInterfaceMAC(unittest.TestCase):
+    def test_get_interface_mac(self):
+        expect_val = '01:02:03:04:05:06'
+        with mock.patch('fcntl.ioctl') as ioctl:
+            ioctl.return_value = ''.join(['\x00' * 18,
+                                          '\x01\x02\x03\x04\x05\x06',
+                                          '\x00' * 232])
+            actual_val = utils.get_interface_mac('eth0')
+        self.assertEquals(actual_val, expect_val)