def setUp(self): super(Abstract, self).setUp() for isl in (self.isl_alpha_beta, self.isl_beta_alpha): isl_info = share.isl_info_payload(isl) command = share.command(isl_info) self.assertTrue(messageclasses.MessageItem(command).handle())
def make_port_down(endpoint): payload = { 'clazz': messageclasses.MT_PORT, 'state': 'DOWN', 'switch_id': endpoint.dpid, 'port_no': endpoint.port} command = share.command(payload) return messageclasses.MessageItem(command).handle()
def make_switch_remove(dpid): payload = { 'clazz': messageclasses.MT_SWITCH, 'state': 'REMOVED', 'switch_id': dpid, 'address': '172.16.0.64', 'hostname': 'test-sw-{}'.format(dpid.replace(':', '')), 'description': 'test switch', 'controller': '172.16.0.1'} command = share.command(payload) return messageclasses.MessageItem(command).handle()
def make_isl_failed(source): command = share.command({ 'clazz': messageclasses.MT_ISL, 'state': 'FAILED', 'latency_ns': 20, 'speed': 1000, 'available_bandwidth': 1000, 'path': [ { 'switch_id': source.dpid, 'port_no': source.port}]}) return messageclasses.MessageItem(command).handle()
def test_update(self): features_request = share.feature_toggle_request(**{ messageclasses.features_status_app_to_transport_map[ messageclasses.FEATURE_REROUTE_ON_ISL_DISCOVERY]: False}) self.assertTrue(share.feed_message(share.command(features_request))) with share.env.neo4j_connect.begin() as tx: cursor = tx.run( 'MATCH (c:config {name: "config"}) RETURN c LIMIT 2') db_config = db.fetch_one(cursor)['c'] self.assertEqual( False, db_config[ messageclasses.features_status_app_to_transport_map[ messageclasses.FEATURE_REROUTE_ON_ISL_DISCOVERY]])
def test_time_update_on_isl_discovery(self): sw_alpha = make_datapath_id(1) sw_beta = make_datapath_id(2) isl_alpha_beta = model.InterSwitchLink( model.NetworkEndpoint(sw_alpha, 2), model.NetworkEndpoint(sw_beta, 2), None) self.assertTrue(make_switch_add(sw_alpha)) self.assertTrue(make_switch_add(sw_beta)) update_point_a = model.TimeProperty.now(milliseconds_precission=True) message = share.command(share.payload_isl_info(isl_alpha_beta)) message['timestamp'] = update_point_a.as_java_timestamp() self.assertTrue(messageclasses.MessageItem(**message).handle()) recovered = model.TimeProperty.new_from_java_timestamp( message['timestamp']) self.assertEquals(update_point_a.value, recovered.value) with neo4j_connect.begin() as tx: isl = isl_utils.fetch(tx, isl_alpha_beta) neo4j_connect.pull(isl) db_ctime = model.TimeProperty.new_from_db(isl['time_create']) self.assertEqual(update_point_a.value, db_ctime.value) db_mtime = model.TimeProperty.new_from_db(isl['time_modify']) self.assertEqual(update_point_a.value, db_mtime.value) # one more update update_point_b = model.TimeProperty.now(milliseconds_precission=True) self.assertNotEqual(update_point_a.value, update_point_b.value) message['timestamp'] = update_point_b.as_java_timestamp() self.assertTrue(messageclasses.MessageItem(**message).handle()) with neo4j_connect.begin() as tx: isl = isl_utils.fetch(tx, isl_alpha_beta) neo4j_connect.pull(isl) db_ctime = model.TimeProperty.new_from_db(isl['time_create']) self.assertEqual(update_point_a.value, db_ctime.value) db_mtime = model.TimeProperty.new_from_db(isl['time_modify']) self.assertEqual(update_point_b.value, db_mtime.value)
def make_isl_moved(isl): command = share.command({ 'clazz': messageclasses.MT_ISL, 'state': 'MOVED', 'latency_ns': 20, 'speed': 1000, 'available_bandwidth': 1000, 'path': [{ 'switch_id': isl.source.dpid, 'port_no': isl.source.port }, { 'switch_id': isl.dest.dpid, 'port_no': isl.dest.port }] }) return messageclasses.MessageItem(**command).handle()
def test_switch_sync(self): sync_switches = self.extract_flow_path_switches(self.flow_alpha) cookies = self.extract_flow_cookies(self.flow_alpha) self.assertTrue(1 < len(sync_switches)) sw = sync_switches[1] sync_request = share.switch_rules_sync(sw, rules=cookies) self.feed_service(share.command(sync_request)) response = self.take_kafka_response( config.KAFKA_SPEAKER_FLOW_TOPIC, offset=1, expect_class=message_utils.MT_COMMAND) self.assertEqual( 'org.openkilda.messaging.command.flow.BatchInstallRequest', response['clazz']) pending_cookies = set(cookies) for command in response['flow_commands']: pending_cookies.remove(command['cookie']) self.assertFalse(pending_cookies)
def _put(self, subject): request = share.link_props_request(subject) payload = share.link_props_put_payload(request) self.feed_service(share.command(payload)) return payload
def make_feature_toggle_request(payload): data = payload.copy() data['clazz'] = ( 'org.openkilda.messaging.command.system.FeatureToggleRequest') message = share.command(data) return messageclasses.MessageItem(**message).handle()