From: Angus Salkeld Date: Fri, 8 Mar 2013 12:04:32 +0000 (+1100) Subject: Add Quantum floating ip tests to improve coverage. X-Git-Tag: 2014.1~789^2 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=a95cc1e2fd5e221098bef7bce2711a1cd466efd7;p=openstack-build%2Fheat-build.git Add Quantum floating ip tests to improve coverage. bug 1152445 Change-Id: If72885228f1d7200f7330a093f3c8a08ad1eea96 Signed-off-by: Angus Salkeld --- diff --git a/heat/tests/test_quantum.py b/heat/tests/test_quantum.py index b1907f19..98cfedfd 100644 --- a/heat/tests/test_quantum.py +++ b/heat/tests/test_quantum.py @@ -25,12 +25,34 @@ from heat.common import exception from heat.common import template_format from heat.engine import properties from heat.engine.resources.quantum import net +from heat.engine.resources.quantum import floatingip from heat.engine.resources.quantum.quantum import QuantumResource as qr from heat.engine import parser class FakeQuantum(): + def create_floatingip(self, props): + return {'floatingip': { + "status": "ACTIVE", + "id": "fc68ea2c-b60b-4b4f-bd82-94ec81110766" + }} + + def delete_floatingip(self, id): + return None + + def show_floatingip(self, id): + return {'floatingip': { + "status": "ACTIVE", + "id": "fc68ea2c-b60b-4b4f-bd82-94ec81110766" + }} + + def update_floatingip(self, id, props): + return {'floatingip': { + "status": "ACTIVE", + "id": "fc68ea2c-b60b-4b4f-bd82-94ec81110766" + }} + def create_network(self, name): return {"network": { "status": "ACTIVE", @@ -155,3 +177,70 @@ class QuantumTest(unittest.TestCase): resource.delete() self.m.VerifyAll() + + +@attr(tag=['unit', 'resource']) +@attr(speed='fast') +class QuantumFloatingIPTest(unittest.TestCase): + def setUp(self): + self.m = mox.Mox() + self.m.StubOutWithMock(floatingip.FloatingIP, 'quantum') + + def tearDown(self): + self.m.UnsetStubs() + + def load_template(self, name='Quantum'): + self.path = os.path.dirname(os.path.realpath(__file__)).\ + replace('heat/tests', 'templates') + f = open("%s/%s.template" % (self.path, name)) + t = template_format.parse(f.read()) + f.close() + return t + + def parse_stack(self, t): + ctx = context.RequestContext.from_dict({ + 'tenant': 'test_tenant', + 'username': 'test_username', + 'password': 'password', + 'auth_url': 'http://localhost:5000/v2.0'}) + stack_name = 'test_stack' + tmpl = parser.Template(t) + params = parser.Parameters(stack_name, tmpl, + {'external_network': 'abcd1234', + 'internal_network': 'xyz1234', + 'internal_subnet': '12.12.12.0'}) + stack = parser.Stack(ctx, stack_name, tmpl, params) + + return stack + + def test_floating_ip(self): + fq = FakeQuantum() + floatingip.FloatingIP.quantum().MultipleTimes().AndReturn(fq) + + self.m.ReplayAll() + + t = self.load_template('Quantum_floating') + stack = self.parse_stack(t) + + fip = stack['floating_ip'] + self.assertEqual(None, fip.create()) + self.assertEqual(floatingip.FloatingIP.CREATE_COMPLETE, fip.state) + fip.validate() + + fip_id = fip.FnGetRefId() + self.assertEqual('fc68ea2c-b60b-4b4f-bd82-94ec81110766', fip_id) + + self.assertEqual('ACTIVE', fip.FnGetAtt('status')) + try: + fip.FnGetAtt('Foo') + raise Exception('Expected InvalidTemplateAttribute') + except exception.InvalidTemplateAttribute: + pass + + self.assertEqual('fc68ea2c-b60b-4b4f-bd82-94ec81110766', + fip.FnGetAtt('id')) + self.assertEqual(floatingip.FloatingIP.UPDATE_REPLACE, + fip.handle_update({})) + self.assertEqual(fip.delete(), None) + + self.m.VerifyAll()