Ejemplo n.º 1
0
    def test_basic(self):
        sot = router.Router()
        self.assertEqual('router', sot.resource_key)
        self.assertEqual('routers', sot.resources_key)
        self.assertEqual('/routers', sot.base_path)
        self.assertEqual('network', sot.service.service_type)
        self.assertTrue(sot.allow_create)
        self.assertTrue(sot.allow_get)
        self.assertTrue(sot.allow_update)
        self.assertTrue(sot.allow_delete)
        self.assertTrue(sot.allow_list)

        self.assertDictEqual(
            {
                "description": "description",
                "flavor_id": "flavor_id",
                "name": "name",
                "status": "status",
                "limit": "limit",
                "marker": "marker",
                "page_reverse": "page_reverse",
                "id": "id",
                "is_admin_state_up": "admin_state_up",
                "is_distributed": "distributed",
                "is_ha": "ha",
                "project_id": "tenant_id"
            },
            sot._query_mapping._mapping
        )
Ejemplo n.º 2
0
 def test_make_it(self):
     sot = router.Router(EXAMPLE)
     self.assertEqual(EXAMPLE['admin_state_up'], sot.admin_state_up)
     self.assertEqual(EXAMPLE['external_gateway_info'],
                      sot.external_gateway_info)
     self.assertEqual(EXAMPLE['id'], sot.id)
     self.assertEqual(EXAMPLE['name'], sot.name)
     self.assertEqual(EXAMPLE['tenant_id'], sot.project_id)
     self.assertEqual(EXAMPLE['status'], sot.status)
Ejemplo n.º 3
0
 def test_basic(self):
     sot = router.Router()
     self.assertEqual('router', sot.resource_key)
     self.assertEqual('routers', sot.resources_key)
     self.assertEqual('/routers', sot.base_path)
     self.assertTrue(sot.allow_create)
     self.assertTrue(sot.allow_fetch)
     self.assertTrue(sot.allow_commit)
     self.assertTrue(sot.allow_delete)
     self.assertTrue(sot.allow_list)
Ejemplo n.º 4
0
 def test_basic(self):
     sot = router.Router()
     self.assertEqual('router', sot.resource_key)
     self.assertEqual('routers', sot.resources_key)
     self.assertEqual('/routers', sot.base_path)
     self.assertEqual('network', sot.service.service_type)
     self.assertTrue(sot.allow_create)
     self.assertTrue(sot.allow_get)
     self.assertTrue(sot.allow_update)
     self.assertTrue(sot.allow_delete)
     self.assertTrue(sot.allow_list)
Ejemplo n.º 5
0
    def test_remove_interface(self):
        sot = router.Router(EXAMPLE)
        response = mock.Mock()
        response.body = {"subnet_id": "3", "port_id": "2"}
        sess = mock.Mock()
        sess.put = mock.MagicMock()
        sess.put.return_value = response

        self.assertEqual(response.body, sot.remove_interface(sess, '3'))

        url = 'v2.0/routers/IDENTIFIER/remove_router_interface'
        body = {"subnet_id": "3"}
        sess.put.assert_called_with(url, service=sot.service, json=body)
Ejemplo n.º 6
0
    def test_add_interface_subnet(self):
        # Add subnet to a router
        sot = router.Router(**EXAMPLE)
        response = mock.Mock()
        response.body = {"subnet_id": "3", "port_id": "2"}
        response.json = mock.Mock(return_value=response.body)
        sess = mock.Mock()
        sess.put = mock.Mock(return_value=response)
        body = {"subnet_id": "3"}
        self.assertEqual(response.body, sot.add_interface(sess, **body))

        url = 'routers/IDENTIFIER/add_router_interface'
        sess.put.assert_called_with(url, json=body)
Ejemplo n.º 7
0
    def test_remove_interface_port(self):
        # Remove port from a router
        sot = router.Router(**EXAMPLE)
        response = mock.Mock()
        response.body = {"subnet_id": "3", "port_id": "3"}
        response.json = mock.Mock(return_value=response.body)
        sess = mock.Mock()
        sess.put = mock.Mock(return_value=response)
        body = {"network_id": 3, "enable_snat": True}
        self.assertEqual(response.body, sot.remove_interface(sess, **body))

        url = 'routers/IDENTIFIER/remove_router_interface'
        sess.put.assert_called_with(url, json=body)
Ejemplo n.º 8
0
    def test_remove_router_gateway(self):
        # Remove gateway to a router
        sot = router.Router(**EXAMPLE_WITH_OPTIONAL)
        response = mock.Mock()
        response.body = {"network_id": "3", "enable_snat": True}
        response.json = mock.Mock(return_value=response.body)
        sess = mock.Mock()
        sess.put = mock.Mock(return_value=response)
        body = {"network_id": 3, "enable_snat": True}
        self.assertEqual(response.body, sot.remove_gateway(sess, **body))

        url = 'routers/IDENTIFIER/remove_gateway_router'
        sess.put.assert_called_with(url, json=body)
Ejemplo n.º 9
0
 def test_add_interface_4xx(self):
     # Neutron may return 4xx, we have to raise if that happens
     sot = router.Router(**EXAMPLE)
     response = mock.Mock()
     msg = 'borked'
     response.body = {'NeutronError': {'message': msg}}
     response.json = mock.Mock(return_value=response.body)
     response.ok = False
     response.status_code = 409
     sess = mock.Mock()
     sess.put = mock.Mock(return_value=response)
     body = {'subnet_id': '3'}
     with testtools.ExpectedException(SDKException, msg):
         sot.add_interface(sess, **body)
Ejemplo n.º 10
0
 def test_make_it_with_optional(self):
     sot = router.Router(EXAMPLE_WITH_OPTIONAL)
     self.assertEqual(EXAMPLE_WITH_OPTIONAL['admin_state_up'],
                      sot.admin_state_up)
     self.assertEqual(EXAMPLE_WITH_OPTIONAL['external_gateway_info'],
                      sot.external_gateway_info)
     self.assertEqual(EXAMPLE_WITH_OPTIONAL['id'], sot.id)
     self.assertEqual(EXAMPLE_WITH_OPTIONAL['name'], sot.name)
     self.assertEqual(EXAMPLE_WITH_OPTIONAL['tenant_id'], sot.project_id)
     self.assertEqual(EXAMPLE_WITH_OPTIONAL['status'], sot.status)
     self.assertEqual(EXAMPLE_WITH_OPTIONAL['ha'], sot.is_ha)
     self.assertEqual(EXAMPLE_WITH_OPTIONAL['distributed'],
                      sot.is_distributed)
     self.assertEqual(EXAMPLE_WITH_OPTIONAL['routes'], sot.routes)
    def test_remove_interface_subnet(self):
        # Remove subnet from a router
        sot = router.Router(**EXAMPLE)
        response = mock.Mock()
        response.body = {"subnet_id": "3", "port_id": "2"}
        response.json = mock.Mock(return_value=response.body)
        sess = mock.Mock()
        sess.put = mock.Mock(return_value=response)
        body = {"subnet_id": "3"}
        self.assertEqual(response.body, sot.remove_interface(sess, **body))

        url = 'routers/IDENTIFIER/remove_router_interface'
        sess.put.assert_called_with(url, endpoint_filter=sot.service,
                                    json=body)
Ejemplo n.º 12
0
    def test_add_router_gateway(self):
        # Add gateway to a router
        sot = router.Router(EXAMPLE_WITH_OPTIONAL)
        response = mock.Mock()
        response.body = {"network_id": "3", "enable_snat": True}
        response.json = mock.Mock(return_value=response.body)
        sess = mock.Mock()
        sess.put = mock.Mock(return_value=response)
        body = {"network_id": 3, "enable_snat": True}
        self.assertEqual(response.body, sot.add_gateway(sess, **body))

        url = 'routers/IDENTIFIER/add_gateway_router'
        sess.put.assert_called_with(url,
                                    endpoint_filter=sot.service,
                                    json=body)
Ejemplo n.º 13
0
 def test_make_it(self):
     sot = router.Router(EXAMPLE)
     self.assertEqual(EXAMPLE['admin_state_up'], sot.admin_state_up)
     self.assertEqual(EXAMPLE['external_gateway_info'],
                      sot.external_gateway_info)
     self.assertEqual(EXAMPLE['id'], sot.id)
     self.assertEqual(EXAMPLE['name'], sot.name)
     self.assertEqual(EXAMPLE['tenant_id'], sot.project_id)
     self.assertEqual(EXAMPLE['status'], sot.status)
     self.assertFalse(sot.is_ha)
     self.assertFalse(sot.is_distributed)
     self.assertEqual(EXAMPLE['routes'], sot.routes)
     self.assertEqual(EXAMPLE['availability_zone_hints'],
                      sot.availability_zone_hints)
     self.assertEqual(EXAMPLE['availability_zones'], sot.availability_zones)
Ejemplo n.º 14
0
 def test_remove_extra_routes(self):
     r = router.Router(**EXAMPLE)
     response = mock.Mock()
     response.headers = {}
     json_body = {'router': {}}
     response.body = json_body
     response.json = mock.Mock(return_value=response.body)
     response.status_code = 200
     sess = mock.Mock()
     sess.put = mock.Mock(return_value=response)
     ret = r.remove_extra_routes(sess, json_body)
     self.assertIsInstance(ret, router.Router)
     self.assertIsInstance(ret.routes, list)
     url = 'routers/IDENTIFIER/remove_extraroutes'
     sess.put.assert_called_with(url, json=json_body)
Ejemplo n.º 15
0
 def test_remove_interface_4xx(self):
     # Neutron may return 4xx for example if a router interface has
     # extra routes referring to it as a nexthop
     sot = router.Router(**EXAMPLE)
     response = mock.Mock()
     msg = 'borked'
     response.body = {'NeutronError': {'message': msg}}
     response.json = mock.Mock(return_value=response.body)
     response.ok = False
     response.status_code = 409
     sess = mock.Mock()
     sess.put = mock.Mock(return_value=response)
     body = {'subnet_id': '3'}
     with testtools.ExpectedException(SDKException, msg):
         sot.remove_interface(sess, **body)
Ejemplo n.º 16
0
    def test_add_interface(self):
        sot = router.Router(EXAMPLE)
        response = mock.Mock()
        response.body = {"subnet_id": "3", "port_id": "2"}
        response.json = mock.Mock(return_value=response.body)
        sess = mock.Mock()
        sess.put = mock.Mock(return_value=response)

        self.assertEqual(response.body, sot.add_interface(sess, '3'))

        url = 'routers/IDENTIFIER/add_router_interface'
        body = {"subnet_id": "3"}
        sess.put.assert_called_with(url,
                                    endpoint_filter=sot.service,
                                    json=body)
Ejemplo n.º 17
0
 def test_make_it_with_optional(self):
     sot = router.Router(**EXAMPLE_WITH_OPTIONAL)
     self.assertFalse(sot.is_admin_state_up)
     self.assertEqual(EXAMPLE_WITH_OPTIONAL['availability_zone_hints'],
                      sot.availability_zone_hints)
     self.assertEqual(EXAMPLE_WITH_OPTIONAL['availability_zones'],
                      sot.availability_zones)
     self.assertEqual(EXAMPLE_WITH_OPTIONAL['description'], sot.description)
     self.assertTrue(sot.is_distributed)
     self.assertEqual(EXAMPLE_WITH_OPTIONAL['external_gateway_info'],
                      sot.external_gateway_info)
     self.assertTrue(sot.is_ha)
     self.assertEqual(EXAMPLE_WITH_OPTIONAL['id'], sot.id)
     self.assertEqual(EXAMPLE_WITH_OPTIONAL['name'], sot.name)
     self.assertEqual(EXAMPLE_WITH_OPTIONAL['routes'], sot.routes)
     self.assertEqual(EXAMPLE_WITH_OPTIONAL['status'], sot.status)
     self.assertEqual(EXAMPLE_WITH_OPTIONAL['tenant_id'], sot.project_id)
Ejemplo n.º 18
0
 def test_make_it(self):
     sot = router.Router(EXAMPLE)
     self.assertTrue(sot.is_admin_state_up)
     self.assertEqual(EXAMPLE['external_gateway_info'],
                      sot.external_gateway_info)
     self.assertEqual(EXAMPLE['id'], sot.id)
     self.assertEqual(EXAMPLE['name'], sot.name)
     self.assertEqual(EXAMPLE['tenant_id'], sot.project_id)
     self.assertEqual(EXAMPLE['status'], sot.status)
     self.assertFalse(sot.is_ha)
     self.assertFalse(sot.is_distributed)
     self.assertEqual(EXAMPLE['routes'], sot.routes)
     self.assertEqual(EXAMPLE['availability_zone_hints'],
                      sot.availability_zone_hints)
     self.assertEqual(EXAMPLE['availability_zones'], sot.availability_zones)
     self.assertEqual(EXAMPLE['description'], sot.description)
     self.assertEqual(EXAMPLE['created_at'], sot.created_at)
     self.assertEqual(EXAMPLE['updated_at'], sot.updated_at)
     self.assertEqual(EXAMPLE['revision_number'], sot.revision_number)
Ejemplo n.º 19
0
 def delete_router(self, **data):
     return router.Router(**data).delete(self.session)
Ejemplo n.º 20
0
 def update_router(self, **data):
     return router.Router(**data).update(self.session)
Ejemplo n.º 21
0
 def create_router(self, **data):
     return router.Router(data).create(self.session)
Ejemplo n.º 22
0
 def get_router(self, **data):
     return router.Router(**data).get(self.session)