def create_node(self, item, parent_nh, user): errors = [] slug = slugify(item['node_type']).replace("_", "-") meta_type = META_TYPES.get(item['node_type'], 'Physical') nh = None if item['node_type'] in GENERIC_TYPES: nh = helpers.get_generic_node_handle(user, item['name'], slug, meta_type) else: try: nh = helpers.create_unique_node_handle(user, item['name'], slug, meta_type) except UniqueNodeError: # Should have been validated, but hey race conditions errors.append( u"Could not create a {} named '{}', since one already exist" .format(item['node_type'], item['name'])) if nh: helpers.dict_update_node( user, nh.handle_id, item, filtered_keys=['node_type', 'children', 'ports']) if item['node_type'] in HAS_RELATION: helpers.set_has(user, parent_nh.get_node(), nh.handle_id) else: helpers.set_location(user, nh.get_node(), parent_nh.handle_id) for child in item.get('children', []): cerrors = self.create_node(child, nh, user) errors += cerrors return errors
def setUp(self): super(SearchTypeaheadPortsCase, self).setUp() self.typeahead_url = "/search/typeahead/ports" site = helpers.create_unique_node_handle(self.user, "UK-HEX", "site", "Location") rack = helpers.get_generic_node_handle(self.user, "A.01", "rack", "Location") helpers.set_has(self.user, site.get_node(), rack.handle_id) odf1 = helpers.create_unique_node_handle(self.user, "test-odf1", "odf", "Physical") odf1_node = odf1.get_node() helpers.set_location(self.user, odf1_node, rack.handle_id) helpers.create_port(odf1_node, "1+2", self.user) helpers.create_port(odf1_node, "3+4", self.user) odf2 = helpers.create_unique_node_handle(self.user, "other-odf2", "odf", "Physical") odf2_node = odf2.get_node() helpers.set_location(self.user, odf2_node, site.handle_id) helpers.create_port(odf2_node, "11+12", self.user) helpers.create_port(odf2_node, "13+14", self.user) router = helpers.create_unique_node_handle(self.user, "uk-hex.nordu.net", "router", "Physical") router_node = router.get_node() helpers.set_location(self.user, router_node, site.handle_id) helpers.create_port(router_node, "ge-0/0/1", self.user) helpers.create_port(router_node, "ge-0/0/2", self.user) helpers.create_port(router_node, "ge-0/1/1", self.user)
def test_decommissioned_equipment(self): self.skipTest('Not working as expected yet.') # Setup test data site = helpers.create_unique_node_handle(self.user, "Test site", "site", "Location") site_node = site.get_node() rack = helpers.get_generic_node_handle(self.user, "A.01", "rack", "Location") helpers.set_has(self.user, site_node, rack.handle_id) odf = helpers.create_unique_node_handle(self.user, "NI-TEST-ODF-01", "odf", "Physical") odf_node = odf.get_node() helpers.dict_update_node(self.user, odf.handle_id, {"max_ports": 24}) helpers.set_location(self.user, odf_node, rack.handle_id) decom_on = helpers.create_unique_node_handle(self.user, "NI-TEST-ON-01", "optical-node", "Physical") decom_on_node = decom_on.get_node() helpers.dict_update_node(self.user, decom_on.handle_id, {"operational_state": "Decommissioned"}) helpers.set_location(self.user, decom_on_node, rack.handle_id) helpers.create_port(decom_on_node, "1", self.user) helpers.create_port(decom_on_node, "2", self.user) # End test data resp = self.client.get(self.get_full_url(site) + "export") self.assertEquals('application/json', resp['Content-Type']) result = resp.json() # verify data self.assertEquals(1, len(result)) rack_result = result[0] self.assertDictContainsSubset({ 'name': 'A.01', 'node_type': 'Rack' }, rack_result) rack_equip = rack_result['children'] # Decommissioned equipment should be gone self.assertEquals(1, len(rack_equip)) self.assertDictContainsSubset( { 'node_type': 'ODF', 'name': 'NI-TEST-ODF-01' }, rack_equip[0]) self.assertEquals(2, len(rack_equip[0]['children']))
def test_populated_site(self): # Setup test data site = helpers.create_unique_node_handle(self.user, "Test site", "site", "Location") site_node = site.get_node() rack = helpers.get_generic_node_handle(self.user, "A.01", "rack", "Location") helpers.set_has(self.user, site_node, rack.handle_id) odf = helpers.create_unique_node_handle(self.user, "NI-TEST-ODF-01", "odf", "Physical") odf_node = odf.get_node() helpers.dict_update_node(self.user, odf.handle_id, {"max_ports": 24}) helpers.set_location(self.user, odf_node, rack.handle_id) helpers.create_port(odf_node, "1", self.user) helpers.create_port(odf_node, "2", self.user) helpers.create_port(odf_node, "3", self.user) router = helpers.create_unique_node_handle( self.user, "ni-test.routers.nordu.net", "router", "Physical") router_node = router.get_node() helpers.dict_update_node(self.user, router.handle_id, { "operational_state": "Testing", "rack_units": 2 }) helpers.set_location(self.user, router_node, rack.handle_id) odf2 = helpers.get_generic_node_handle(self.user, "NI-TEST-ODF-02", "odf", "Physical") odf2_node = odf2.get_node() helpers.set_location(self.user, odf2_node, site.handle_id) # Done setting up testdata resp = self.client.get(self.get_full_url(site) + "export") self.assertEquals('application/json', resp['Content-Type']) result = resp.json() # verify data self.assertEquals(2, len(result)) self.assertDictContainsSubset({ 'name': 'A.01', 'node_type': 'Rack' }, result[0]) self.assertDictContainsSubset( { 'node_type': 'ODF', 'name': 'NI-TEST-ODF-02' }, result[1]) # Check racked equipment rack_equp = result[0]['children'] self.assertEquals(2, len(rack_equp)) odf1_result = rack_equp[0] self.assertDictContainsSubset( { 'node_type': 'ODF', 'name': 'NI-TEST-ODF-01', 'max_ports': 24 }, odf1_result) # Check ODF ports odf1_ports = odf1_result['children'] self.assertEquals(3, len(odf1_ports)) self.assertDictContainsSubset( { 'node_type': 'Port', 'name': '1', 'port_type': '' }, odf1_ports[0]) self.assertDictContainsSubset( { 'node_type': 'Port', 'name': '2', 'description': '' }, odf1_ports[1]) self.assertDictContainsSubset({ 'node_type': 'Port', 'name': '3' }, odf1_ports[2]) # Check router router = rack_equp[1] self.assertDictContainsSubset( { 'node_type': 'Router', 'name': 'ni-test.routers.nordu.net' }, router)