def setUp(self): self.sys_path_save = sys.path self.cwd_save = os.getcwd() config = os.path.join(test_path, "test_config.yaml") from xosconfig import Config Config.clear() Config.init(config, "synchronizer-config-schema.yaml") from xossynchronizer.mock_modelaccessor_build import ( build_mock_modelaccessor, ) build_mock_modelaccessor(sync_lib_dir, xos_dir, services_dir=None, service_xprotos=[]) # The test config.yaml references files in `xos-synchronizer-tests/` so make sure we're in the parent # directory of the test directory. os.chdir(os.path.join(test_path, "..")) import xossynchronizer.event_loop reload(xossynchronizer.event_loop) import xossynchronizer.backend reload(xossynchronizer.backend) from xossynchronizer.modelaccessor import model_accessor b = xossynchronizer.backend.Backend(model_accessor=model_accessor) steps_dir = Config.get("steps_dir") self.steps = b.load_sync_step_modules(steps_dir) self.synchronizer = xossynchronizer.event_loop.XOSObserver(self.steps, model_accessor)
def setUp(self): self.sys_path_save = sys.path sys.path.append(xos_dir) sys.path.append(os.path.join(xos_dir, 'synchronizers', 'new_base')) config = os.path.join(test_path, "../test_config.yaml") from xosconfig import Config Config.clear() Config.init(config, 'synchronizer-config-schema.yaml') from synchronizers.new_base.mock_modelaccessor_build import build_mock_modelaccessor build_mock_modelaccessor(xos_dir, services_dir, [ get_models_fn("hippie-oss", "hippie-oss.xproto"), get_models_fn("olt-service", "volt.xproto"), get_models_fn("rcord", "rcord.xproto") ]) import synchronizers.new_base.modelaccessor from model_policy_hippieossserviceinstance import OSSServiceInstancePolicy, model_accessor from mock_modelaccessor import MockObjectList # import all class names to globals for (k, v) in model_accessor.all_model_classes.items(): globals()[k] = v # Some of the functions we call have side-effects. For example, creating a VSGServiceInstance may lead to creation of # tags. Ideally, this wouldn't happen, but it does. So make sure we reset the world. model_accessor.reset_all_object_stores() self.policy = OSSServiceInstancePolicy() self.si = Mock() self.si.owner = Mock()
def setUp(self): global XOSKafkaThread, Config, log self.sys_path_save = sys.path self.cwd_save = os.getcwd() config = os.path.join(test_path, "test_config.yaml") from xosconfig import Config Config.clear() Config.init(config, "synchronizer-config-schema.yaml") from xossynchronizer.mock_modelaccessor_build import ( build_mock_modelaccessor, ) build_mock_modelaccessor(sync_lib_dir, xos_dir, services_dir=None, service_xprotos=[]) from xossynchronizer.modelaccessor import model_accessor # The test config.yaml references files in `xos-synchronizer-tests/` so make sure we're in the parent # directory of the test directory. os.chdir(os.path.join(test_path, "..")) from xossynchronizer.event_engine import XOSKafkaThread, XOSEventEngine self.event_steps_dir = Config.get("event_steps_dir") self.event_engine = XOSEventEngine(model_accessor=model_accessor, log=log)
def setUp(self): global mock_enumerator, event_loop self.sys_path_save = sys.path self.cwd_save = os.getcwd() sys.path.append(xos_dir) sys.path.append(os.path.join(xos_dir, 'synchronizers', 'new_base')) sys.path.append(os.path.join(xos_dir, 'synchronizers', 'new_base', 'tests', 'steps')) config = os.path.join(test_path, "test_config.yaml") from xosconfig import Config Config.clear() Config.init(config, 'synchronizer-config-schema.yaml') from synchronizers.new_base.mock_modelaccessor_build import build_mock_modelaccessor build_mock_modelaccessor(xos_dir, services_dir=None, service_xprotos=[]) os.chdir(os.path.join(test_path, '..')) # config references tests/model-deps import event_loop reload(event_loop) import backend reload(backend) from mock_modelaccessor import mock_enumerator from modelaccessor import model_accessor # import all class names to globals for (k, v) in model_accessor.all_model_classes.items(): globals()[k] = v b = backend.Backend() steps_dir = Config.get("steps_dir") self.steps = b.load_sync_step_modules(steps_dir) self.synchronizer = event_loop.XOSObserver(self.steps)
def setUp(self): self.sys_path_save = sys.path self.cwd_save = os.getcwd() config = os.path.join(test_path, "test_config.yaml") from xosconfig import Config Config.clear() Config.init(config, "synchronizer-config-schema.yaml") from xossynchronizer.mock_modelaccessor_build import ( build_mock_modelaccessor, ) build_mock_modelaccessor(sync_lib_dir, xos_dir, services_dir=None, service_xprotos=[]) os.chdir(os.path.join(test_path, "..")) # config references xos-synchronizer-tests/model-deps import xossynchronizer.event_loop reload(xossynchronizer.event_loop) import xossynchronizer.backend reload(xossynchronizer.backend) from xossynchronizer.modelaccessor import model_accessor # import all class names to globals for (k, v) in model_accessor.all_model_classes.items(): globals()[k] = v b = xossynchronizer.backend.Backend(model_accessor=model_accessor) steps_dir = Config.get("steps_dir") self.steps = b.load_sync_step_modules(steps_dir) self.synchronizer = xossynchronizer.event_loop.XOSObserver(self.steps, model_accessor)
def setUp(self): self.sys_path_save = sys.path # Setting up the config module from xosconfig import Config config = os.path.join(test_path, "test_config.yaml") Config.clear() Config.init(config, "synchronizer-config-schema.yaml") # END Setting up the config module from xossynchronizer.mock_modelaccessor_build import build_mock_modelaccessor # FIXME this is to get jenkins to pass the tests, somehow it is running tests in a different order # and apparently it is not overriding the generated model accessor build_mock_modelaccessor(sync_lib_dir, xos_dir, services_dir, []) import xossynchronizer.modelaccessor # import all class names to globals for ( k, v, ) in xossynchronizer.modelaccessor.model_accessor.all_model_classes.items(): globals()[k] = v self.log = Mock()
def setUp(self): global ComputeNodePolicy, MockObjectList self.sys_path_save = sys.path config = os.path.join(test_path, "../test_config.yaml") from xosconfig import Config Config.clear() Config.init(config, 'synchronizer-config-schema.yaml') from xossynchronizer.mock_modelaccessor_build import mock_modelaccessor_config mock_modelaccessor_config(test_path, [("fabric", "fabric.xproto")]) import xossynchronizer.modelaccessor import mock_modelaccessor imp.reload(mock_modelaccessor) # in case nose2 loaded it in a previous test imp.reload(xossynchronizer.modelaccessor) # in case nose2 loaded it in a previous test from model_policy_compute_nodes import ComputeNodePolicy, model_accessor self.model_accessor = model_accessor from mock_modelaccessor import MockObjectList # import all class names to globals for (k, v) in model_accessor.all_model_classes.items(): globals()[k] = v # Some of the functions we call have side-effects. For example, creating a VSGServiceInstance may lead to # creation of tags. Ideally, this wouldn't happen, but it does. So make sure we reset the world. model_accessor.reset_all_object_stores() self.policy = ComputeNodePolicy self.model = Mock()
def setUp(self): config = os.path.abspath( os.path.dirname(os.path.realpath(__file__)) + "/test_config.yaml") Config.clear() # in case left unclean by a previous test case Config.init(config) self.mock_backup_operation = MagicMock() self.mock_backup_file = MagicMock() sys.modules["core"] = Mock() sys.modules["core.models"] = Mock( BackupOperation=self.mock_backup_operation, BackupFile=self.mock_backup_file) # needed because decorators.py imports xos.exceptions self.sys_path_save = sys.path sys.path = [XOS_DIR] + sys.path import decorators decorators.disable_check_db_connection_decorator = True import backupsetwatcher self.backupsetwatcher = backupsetwatcher self.setUpPyfakefs() self.server = MockServer() self.watcher = backupsetwatcher.BackupSetWatcherThread(self.server)
def setUp(self): self.sys_path_save = sys.path sys.path.append(xos_dir) sys.path.append(os.path.join(xos_dir, "synchronizers", "new_base")) # Setting up the config module from xosconfig import Config config = os.path.join(test_path, "test_config.yaml") Config.clear() Config.init(config, "synchronizer-config-schema.yaml") # END Setting up the config module from synchronizers.new_base.mock_modelaccessor_build import ( build_mock_modelaccessor, ) # FIXME this is to get jenkins to pass the tests, somehow it is running tests in a different order # and apparently it is not overriding the generated model accessor build_mock_modelaccessor(xos_dir, services_dir, []) import synchronizers.new_base.modelaccessor # import all class names to globals for ( k, v, ) in (synchronizers.new_base.modelaccessor.model_accessor. all_model_classes.items()): globals()[k] = v self.log = Mock()
def setUp(self): self.sys_path_save = sys.path config = os.path.join(test_path, "../test_config.yaml") from xosconfig import Config Config.clear() Config.init(config, 'synchronizer-config-schema.yaml') from xossynchronizer.mock_modelaccessor_build import mock_modelaccessor_config mock_modelaccessor_config(test_path, [("ntt-workflow-driver", "ntt-workflow-driver.xproto"), ("olt-service", "volt.xproto"), ("rcord", "rcord.xproto")]) import xossynchronizer.modelaccessor import mock_modelaccessor reload(mock_modelaccessor) # in case nose2 loaded it in a previous test reload(xossynchronizer.modelaccessor) # in case nose2 loaded it in a previous test from xossynchronizer.modelaccessor import model_accessor from model_policy_ntt_workflow_driver_serviceinstance import NttWorkflowDriverServiceInstancePolicy, NttHelpers self.NttHelpers = NttHelpers # import all class names to globals for (k, v) in model_accessor.all_model_classes.items(): globals()[k] = v # Some of the functions we call have side-effects. For example, creating a VSGServiceInstance may lead to # creation of tags. Ideally, this wouldn't happen, but it does. So make sure we reset the world. model_accessor.reset_all_object_stores() self.policy = NttWorkflowDriverServiceInstancePolicy(model_accessor=model_accessor) self.si = NttWorkflowDriverServiceInstance() self.si.owner = NttWorkflowDriverService() self.si.serial_number = "BRCM1234"
def setUp(self): global VOLTServiceInstancePolicy, MockObjectList self.sys_path_save = sys.path config = os.path.join(test_path, "../test_config.yaml") from xosconfig import Config Config.clear() Config.init(config, 'synchronizer-config-schema.yaml') from xossynchronizer.mock_modelaccessor_build import mock_modelaccessor_config mock_modelaccessor_config(test_path, [("olt-service", "volt.xproto"), ("rcord", "rcord.xproto")]) import xossynchronizer.modelaccessor import mock_modelaccessor reload(mock_modelaccessor) # in case nose2 loaded it in a previous test reload(xossynchronizer.modelaccessor) # in case nose2 loaded it in a previous test from xossynchronizer.modelaccessor import model_accessor self.model_accessor = model_accessor from mock_modelaccessor import MockObjectList from model_policy_voltserviceinstance import VOLTServiceInstancePolicy # import all class names to globals for (k, v) in model_accessor.all_model_classes.items(): globals()[k] = v # Some of the functions we call have side-effects. For example, creating a ServiceInstance may lead to creation of # tags. Ideally, this wouldn't happen, but it does. So make sure we reset the world. model_accessor.reset_all_object_stores() self.policy = VOLTServiceInstancePolicy(model_accessor=self.model_accessor) self.si = Mock()
def setUp(self): self.sys_path_save = sys.path # Setting up the config module from xosconfig import Config config = os.path.join(test_path, "../test_config.yaml") Config.clear() Config.init(config, "synchronizer-config-schema.yaml") # END Setting up the config module from xossynchronizer.mock_modelaccessor_build import mock_modelaccessor_config mock_modelaccessor_config(test_path, [ ("onos-service", "onos.xproto"), ]) import xossynchronizer.modelaccessor import mock_modelaccessor reload( mock_modelaccessor) # in case nose2 loaded it in a previous test reload(xossynchronizer.modelaccessor ) # in case nose2 loaded it in a previous test from sync_onos_service import SyncONOSService, model_accessor self.model_accessor = model_accessor # import all class names to globals for (k, v) in model_accessor.all_model_classes.items(): globals()[k] = v self.sync_step = SyncONOSService self.onos = Mock(spec=[ 'id', 'name', "rest_hostname", "rest_port", "rest_username", "rest_password", "class_names" ]) self.onos.id = 1 self.onos.name = "onos" self.onos.rest_hostname = "onos-url" self.onos.rest_port = "8181" self.onos.rest_username = "******" self.onos.rest_password = "******" self.onos.class_names = "ONOSService" self.service = Mock() self.service.id = 1 self.service.serviceattribute_dict = {} self.service.leaf_model = self.onos self.onos_service_attribute = Mock( spec=['id', 'service', 'name', 'value']) self.onos_service_attribute.service = self.service self.onos_service_attribute.name = "/onos/v1/network/configuration/apps/org.opencord.olt" self.onos_service_attribute.value = { "kafka": { "bootstrapServers": "cord-kafka-kafka.default.svc.cluster.local:9092" } }
def setUp(self): self.sys_path_save = sys.path self.cwd_save = os.getcwd() config = os.path.join(test_path, "test_config.yaml") from xosconfig import Config Config.clear() Config.init(config, "synchronizer-config-schema.yaml") from xossynchronizer.mock_modelaccessor_build import ( build_mock_modelaccessor, ) build_mock_modelaccessor(sync_lib_dir, xos_dir, services_dir=None, service_xprotos=[]) # The test config.yaml references files in `xos-synchronizer-tests/` so make sure we're in the parent # directory of the test directory. os.chdir(os.path.join(test_path, "..")) import xossynchronizer.event_loop reload(xossynchronizer.event_loop) import xossynchronizer.backend reload(xossynchronizer.backend) from xossynchronizer.modelaccessor import model_accessor b = xossynchronizer.backend.Backend(model_accessor=model_accessor) steps_dir = Config.get("steps_dir") self.steps = b.load_sync_step_modules(steps_dir) self.synchronizer = xossynchronizer.event_loop.XOSObserver( self.steps, model_accessor)
def setUp(self): global XOSKafkaThread, Config, log self.sys_path_save = sys.path self.cwd_save = os.getcwd() sys.path.append(xos_dir) sys.path.append(os.path.join(xos_dir, "synchronizers", "new_base")) sys.path.append( os.path.join(xos_dir, "synchronizers", "new_base", "tests", "event_steps") ) config = os.path.join(test_path, "test_config.yaml") from xosconfig import Config Config.clear() Config.init(config, "synchronizer-config-schema.yaml") from synchronizers.new_base.mock_modelaccessor_build import ( build_mock_modelaccessor, ) build_mock_modelaccessor(xos_dir, services_dir=None, service_xprotos=[]) os.chdir(os.path.join(test_path, "..")) # config references tests/model-deps from event_engine import XOSKafkaThread, XOSEventEngine self.event_steps_dir = Config.get("event_steps_dir") self.event_engine = XOSEventEngine(log)
def setUp(self): self.sys_path_save = sys.path # Setting up the config module from xosconfig import Config config = os.path.join(test_path, "../test_config.yaml") Config.clear() Config.init(config, "synchronizer-config-schema.yaml") # END Setting up the config module from xossynchronizer.mock_modelaccessor_build import mock_modelaccessor_config mock_modelaccessor_config( test_path, [("ntt-workflow-driver", "ntt-workflow-driver.xproto"), ("olt-service", "volt.xproto"), ("rcord", "rcord.xproto")]) import xossynchronizer.modelaccessor import mock_modelaccessor reload( mock_modelaccessor) # in case nose2 loaded it in a previous test reload(xossynchronizer.modelaccessor ) # in case nose2 loaded it in a previous test from xossynchronizer.modelaccessor import model_accessor from onu_event import ONUEventStep # import all class names to globals for (k, v) in model_accessor.all_model_classes.items(): globals()[k] = v self.model_accessor = model_accessor self.log = Mock() self.event_step = ONUEventStep(model_accessor=self.model_accessor, log=self.log) self.event = Mock() self.event_dict = { 'status': 'activated', 'serialNumber': 'BRCM1234', 'deviceId': 'of:109299321', 'portNumber': '16' } self.event.value = json.dumps(self.event_dict) self.pppoe = NttWorkflowDriverService(name="ntt-workflow-driver") self.pon_port = PONPort() self.pon_port.port_no = 1234 self.onu = ONUDevice() self.onu.pon_port = self.pon_port self.onu.serial_number = "BRCM1234" self.onu.mac_address = "0a0a0a" self.technologyProfile = TechnologyProfile() self.technologyProfile.profile_id = 64 self.technologyProfile.profile_value = '{"profile_type": "EPON","epon_attribute": {"package_type": "A"}}'
def setUp(self): global VEGTenantPolicy, LeastLoadedNodeScheduler, MockObjectList self.sys_path_save = sys.path sys.path.append(xos_dir) sys.path.append(os.path.join(xos_dir, 'synchronizers', 'new_base')) config = os.path.join(test_path, "test_config.yaml") from xosconfig import Config Config.clear() Config.init(config, 'synchronizer-config-schema.yaml') from synchronizers.new_base.mock_modelaccessor_build import build_mock_modelaccessor build_mock_modelaccessor(xos_dir, services_dir, [ get_models_fn("vEG", "veg.xproto"), get_models_fn("addressmanager", "addressmanager.xproto") ]) import synchronizers.new_base.modelaccessor import synchronizers.new_base.model_policies.model_policy_tenantwithcontainer import model_policy_vegtenant from model_policy_vegtenant import VEGTenantPolicy, model_accessor from synchronizers.new_base.model_policies.model_policy_tenantwithcontainer import LeastLoadedNodeScheduler from mock_modelaccessor import MockObjectList # import all class names to globals for (k, v) in model_accessor.all_model_classes.items(): globals()[k] = v # Some of the functions we call have side-effects. For example, creating a VEGTenant may lead to creation of # tags. Ideally, this wouldn't happen, but it does. So make sure we reset the world. model_accessor.reset_all_object_stores() # attic functions that are not present in the mock model accessor VEGTenant.volt = PropertyMock(return_value=None) AddressManagerServiceInstance.set_attribute = Mock() self.policy = VEGTenantPolicy() self.tenant = VEGTenant() self.user = User(email="*****@*****.**") self.tenant = VEGTenant(creator=self.user, id=1) self.flavor = Flavor(name="m1.small") self.npt_ctag = NetworkParameterType(name="c_tag", id=1) self.npt_stag = NetworkParameterType(name="s_tag", id=2) self.npt_neutron_port_name = NetworkParameterType( name="neutron_port_name", id=3) self.node = Node(hostname="my.node.com") self.slice = Slice(name="mysite_test1", default_flavor=self.flavor, default_isolation="vm") self.priv_template = NetworkTemplate(name="access_network", visibility="private") self.priv_network = Network(name="mysite_test1_private", template=self.priv_template) self.image = Image(name="trusty-server-multi-nic") self.deployment = Deployment(name="testdeployment") Tag.objects.item_list = []
def setUp(self): config = os.path.abspath( os.path.dirname(os.path.realpath(__file__)) + "/test_config.yaml") Config.clear() # in case left unclean by a previous test case Config.init(config) import backuphandler self.handler_postgres = backuphandler.BackupHandler_postgres()
def setUp(self): self.sys_path_save = sys.path # Setting up the config module from xosconfig import Config config = os.path.join(test_path, "../test_config.yaml") Config.clear() Config.init(config, "synchronizer-config-schema.yaml") # END Setting up the config module from xossynchronizer.mock_modelaccessor_build import mock_modelaccessor_config mock_modelaccessor_config(test_path, [("vrouter", "vrouter.xproto")]) import xossynchronizer.modelaccessor import mock_modelaccessor reload( mock_modelaccessor) # in case nose2 loaded it in a previous test reload(xossynchronizer.modelaccessor ) # in case nose2 loaded it in a previous test from sync_routes import SyncRoutes, model_accessor self.model_accessor = model_accessor # import all class names to globals for (k, v) in model_accessor.all_model_classes.items(): globals()[k] = v self.sync_step = SyncRoutes self.sync_step.log = Mock() # mock onos-fabric onos_fabric = Mock() onos_fabric.name = "onos-fabric" onos_fabric.rest_hostname = "onos-fabric" onos_fabric.rest_port = "8181" onos_fabric.rest_username = "******" onos_fabric.rest_password = "******" onos_fabric_base = Mock() onos_fabric_base.leaf_model = onos_fabric self.fabric = Mock() self.fabric.name = "fabric" self.fabric.provider_services = [onos_fabric_base] self.vrouter = Mock() self.vrouter.name = "vrouter" self.vrouter.provider_services = [self.fabric] # create a mock VRouterStaticRoute instance self.o = Mock() self.o.id = 1 self.o.vrouter.owner = self.vrouter self.o.tologdict.return_value = {}
def setUp(self): from xosconfig import Config test_path = os.path.abspath(os.path.dirname(os.path.realpath(__file__))) config = os.path.join(test_path, "test_config.yaml") Config.clear() Config.init(config, "synchronizer-config-schema.yaml") if USE_FAKE_STUB: sys.path.append(PARENT_DIR)
def setUp(self): global DeferredException self.sys_path_save = sys.path sys.path.append(xos_dir) sys.path.append(os.path.join(xos_dir, 'synchronizers', 'new_base')) # Setting up the config module from xosconfig import Config config = os.path.join(test_path, "../test_vsg_hw_config.yaml") Config.clear() Config.init(config, "synchronizer-config-schema.yaml") # END Setting up the config module from synchronizers.new_base.mock_modelaccessor_build import build_mock_modelaccessor build_mock_modelaccessor(xos_dir, services_dir, [get_models_fn("vsg-hw", "vsg-hw.xproto")]) import synchronizers.new_base.modelaccessor from sync_vsg_hw_service_instance import SyncVSGHWServiceInstance, model_accessor # import all class names to globals for (k, v) in model_accessor.all_model_classes.items(): globals()[k] = v self.sync_step = SyncVSGHWServiceInstance # mock onos-fabric onos_fabric = Mock() onos_fabric.name = "onos-fabric" onos_fabric.rest_hostname = "onos-fabric" onos_fabric.rest_port = "8181" onos_fabric.rest_username = "******" onos_fabric.rest_password = "******" # mock generic service svc = Mock() svc.name = "onos-fabric" svc.leaf_model = onos_fabric # mock vsg-hw service self.vsg_service = Mock() self.vsg_service.provider_services = [svc] # create a mock vsg-hw service instance o = Mock() o.id = 1 o.owner = self.vsg_service o.tologdict.return_value = {} si = Mock() si.get_westbound_service_instance_properties = mock_get_westbound_service_instance_properties self.o = o self.si = si
def setUp(self): self.sys_path_save = sys.path # Setting up the config module from xosconfig import Config config = os.path.join(test_path, "../test_config.yaml") Config.clear() Config.init(config, "synchronizer-config-schema.yaml") # END Setting up the config module from xossynchronizer.mock_modelaccessor_build import mock_modelaccessor_config mock_modelaccessor_config(test_path, [("vrouter", "vrouter.xproto")]) import xossynchronizer.modelaccessor import mock_modelaccessor reload(mock_modelaccessor) # in case nose2 loaded it in a previous test reload(xossynchronizer.modelaccessor) # in case nose2 loaded it in a previous test from sync_routes import SyncRoutes, model_accessor self.model_accessor = model_accessor # import all class names to globals for (k, v) in model_accessor.all_model_classes.items(): globals()[k] = v self.sync_step = SyncRoutes self.sync_step.log = Mock() # mock onos-fabric onos_fabric = Mock() onos_fabric.name = "onos-fabric" onos_fabric.rest_hostname = "onos-fabric" onos_fabric.rest_port = "8181" onos_fabric.rest_username = "******" onos_fabric.rest_password = "******" onos_fabric_base = Mock() onos_fabric_base.leaf_model = onos_fabric self.fabric = Mock() self.fabric.name = "fabric" self.fabric.provider_services = [onos_fabric_base] self.vrouter = Mock() self.vrouter.name = "vrouter" self.vrouter.provider_services = [self.fabric] # create a mock VRouterStaticRoute instance self.o = Mock() self.o.id = 1 self.o.vrouter.owner = self.vrouter self.o.tologdict.return_value = {}
def setUp(self): from xosconfig import Config test_path = os.path.abspath(os.path.dirname( os.path.realpath(__file__))) config = os.path.join(test_path, "test_config.yaml") Config.clear() Config.init(config, "synchronizer-config-schema.yaml") if USE_FAKE_STUB: sys.path.append(PARENT_DIR)
def setup_sync_unit_test(test_path, globals_dict, models, config_fn="test_config.yaml"): """ Perform the common steps associated with setting up a synchronizer unit test. 1) Import xosconfig.Config and set it up to test_config.yaml in the current dir 2) Build the mock modelaccessor and import it 3) Import all model accessor classes into global space Arguments: test_path - path to the test case that is being run globals_dict - a dictionary to add global models to models - a list of pairs (service_name, xproto_name) config_fn - filename of config file) Returns: Dictionary containing the following: sys_path_save: the original sys.path model_accessor: model accessor class Config: the Config object xos_dir: xos directory services_dir: services directory """ sys_path_save = sys.path # Setting up the config module from xosconfig import Config config = os.path.join(test_path, config_fn) Config.clear() Config.init(config, "synchronizer-config-schema.yaml") from xossynchronizer.mock_modelaccessor_build import mock_modelaccessor_config mock_modelaccessor_config(test_path, models) import xossynchronizer.modelaccessor reload(xossynchronizer.modelaccessor ) # in case nose2 loaded it in a previous testp from xossynchronizer.modelaccessor import model_accessor # modelaccessor.py will have ensure mock_modelaccessor is in sys.path from mock_modelaccessor import MockObjectList # import all class names to globals for (k, v) in model_accessor.all_model_classes.items(): globals_dict[k] = v return { "sys_path_save": sys_path_save, "model_accessor": model_accessor, "Config": Config, "MockObjectList": MockObjectList }
def setUp(self): global DeferredException self.sys_path_save = sys.path sys.path.append(xos_dir) sys.path.append(os.path.join(xos_dir, "synchronizers", "new_base")) # Setting up the config module from xosconfig import Config config = os.path.join(test_path, "../test_fabric_crossconnect_config.yaml") Config.clear() Config.init(config, "synchronizer-config-schema.yaml") # END Setting up the config module from synchronizers.new_base.mock_modelaccessor_build import ( build_mock_modelaccessor, ) build_mock_modelaccessor( xos_dir, services_dir, [ get_models_fn("fabric-crossconnect", "fabric-crossconnect.xproto") ], ) from synchronizers.new_base.modelaccessor import model_accessor from sync_fabric_crossconnect_service_instance import ( SyncFabricCrossconnectServiceInstance, DeferredException, ) # import all class names to globals for (k, v) in model_accessor.all_model_classes.items(): globals()[k] = v self.sync_step = SyncFabricCrossconnectServiceInstance self.sync_step.log = Mock() # mock onos-fabric self.onos_fabric = Service( name="onos-fabric", rest_hostname="onos-fabric", rest_port="8181", rest_username="******", rest_password="******", ) self.service = FabricCrossconnectService( name="fcservice", provider_services=[self.onos_fabric])
def setUp(self): self.sys_path_save = sys.path sys.path.append(xos_dir) sys.path.append(os.path.join(xos_dir, 'synchronizers', 'new_base')) config = os.path.join(test_path, "../test_config.yaml") from xosconfig import Config Config.clear() Config.init(config, 'synchronizer-config-schema.yaml') from synchronizers.new_base.mock_modelaccessor_build import build_mock_modelaccessor build_mock_modelaccessor(xos_dir, services_dir, [ get_models_fn("hippie-oss", "hippie-oss.xproto"), get_models_fn("olt-service", "volt.xproto"), get_models_fn("rcord", "rcord.xproto") ]) import synchronizers.new_base.modelaccessor from model_policy_hippieossservice import OSSServicePolicy, model_accessor from mock_modelaccessor import MockObjectList self.MockObjectList = MockObjectList # import all class names to globals for (k, v) in model_accessor.all_model_classes.items(): globals()[k] = v # Some of the functions we call have side-effects. For example, creating a VSGServiceInstance may lead to creation of # tags. Ideally, this wouldn't happen, but it does. So make sure we reset the world. model_accessor.reset_all_object_stores() self.policy = OSSServicePolicy() self.service = HippieOSSService( id=5367, whitelist_entries=[], ) # needs to be enabled self.si1 = HippieOSSServiceInstance(valid="awaiting", serial_number="BRCM111") # needs to be enabled self.si2 = HippieOSSServiceInstance(valid="invalid", serial_number="BRCM222") # remains disabled self.si3 = HippieOSSServiceInstance(valid="invalid", serial_number="BRCM333") # needs to be disabled self.si4 = HippieOSSServiceInstance(valid="valid", serial_number="BRCM444")
def setUp(self): global DeferredException self.sys_path_save = sys.path # Setting up the config module from xosconfig import Config config = os.path.join(test_path, "../test_config.yaml") Config.clear() Config.init(config, "synchronizer-config-schema.yaml") # END Setting up the config module from xossynchronizer.mock_modelaccessor_build import mock_modelaccessor_config mock_modelaccessor_config(test_path, [("fabric", "fabric.xproto")]) import xossynchronizer.modelaccessor import mock_modelaccessor reload( mock_modelaccessor) # in case nose2 loaded it in a previous test reload(xossynchronizer.modelaccessor ) # in case nose2 loaded it in a previous test from xossynchronizer.modelaccessor import model_accessor self.model_accessor = model_accessor from sync_fabric_switch import SyncFabricSwitch # import all class names to globals for (k, v) in model_accessor.all_model_classes.items(): globals()[k] = v self.sync_step = SyncFabricSwitch self.sync_step.log = Mock() # mock onos-fabric onos_fabric = Mock() onos_fabric.name = "onos-fabric" onos_fabric.rest_hostname = "onos-fabric" onos_fabric.rest_port = "8181" onos_fabric.rest_username = "******" onos_fabric.rest_password = "******" onos_fabric_base = Mock() onos_fabric_base.leaf_model = onos_fabric self.fabric = Mock() self.fabric.name = "fabric" self.fabric.provider_services = [onos_fabric_base] # create a mock Switch instance self.o = Mock() self.o.name = "MockSwitch" self.o.ofId = "of:1234"
def setUp(self): self.sys_path_save = sys.path # Setting up the config module from xosconfig import Config config = os.path.join(test_path, "../test_config.yaml") Config.clear() Config.init(config, "synchronizer-config-schema.yaml") from multistructlog import create_logger log = create_logger(Config().get('logging')) # END Setting up the config module from xossynchronizer.mock_modelaccessor_build import mock_modelaccessor_config mock_modelaccessor_config(test_path, [("dt-workflow-driver", "dt-workflow-driver.xproto"), ("olt-service", "volt.xproto"), ("rcord", "rcord.xproto")]) import xossynchronizer.modelaccessor import mock_modelaccessor reload(mock_modelaccessor) # in case nose2 loaded it in a previous test reload(xossynchronizer.modelaccessor) # in case nose2 loaded it in a previous test from xossynchronizer.modelaccessor import model_accessor from pppoe_event import SubscriberPppoeEventStep # import all class names to globals for (k, v) in model_accessor.all_model_classes.items(): globals()[k] = v self.model_accessor = model_accessor self.log = log self.event_step = SubscriberPppoeEventStep(model_accessor=self.model_accessor, log=self.log) self.event = Mock() self.volt = Mock() self.volt.name = "vOLT" self.volt.leaf_model = Mock() # self.subscriber = RCORDSubscriber() # self.subscriber.onu_device = "BRCM1234" # self.subscriber.save = Mock() self.mac_address = "00:AA:00:00:00:01" self.ip_address = "192.168.3.5" self.pppoe_session_id = "12" self.si = DtWorkflowDriverServiceInstance() self.si.serial_number = "BRCM1234" self.si.save = Mock()
def setUp(self): global VSGServiceInstancePolicy, LeastLoadedNodeScheduler, MockObjectList self.sys_path_save = sys.path sys.path.append(xos_dir) sys.path.append(os.path.join(xos_dir, 'synchronizers', 'new_base')) config = os.path.join(test_path, "test_config.yaml") from xosconfig import Config Config.clear() Config.init(config, 'synchronizer-config-schema.yaml') from synchronizers.new_base.mock_modelaccessor_build import build_mock_modelaccessor build_mock_modelaccessor(xos_dir, services_dir, [get_models_fn("vsg", "vsg.xproto"), get_models_fn("addressmanager", "addressmanager.xproto")]) import synchronizers.new_base.modelaccessor import synchronizers.new_base.model_policies.model_policy_tenantwithcontainer import model_policy_vsgserviceinstance from model_policy_vsgserviceinstance import VSGServiceInstancePolicy, model_accessor from synchronizers.new_base.model_policies.model_policy_tenantwithcontainer import LeastLoadedNodeScheduler from mock_modelaccessor import MockObjectList # import all class names to globals for (k, v) in model_accessor.all_model_classes.items(): globals()[k] = v # Some of the functions we call have side-effects. For example, creating a VSGServiceInstance may lead to creation of # tags. Ideally, this wouldn't happen, but it does. So make sure we reset the world. model_accessor.reset_all_object_stores() # attic functions that are not present in the mock model accessor VSGServiceInstance.volt = PropertyMock(return_value = None) AddressManagerServiceInstance.set_attribute = Mock() self.policy = VSGServiceInstancePolicy() self.tenant = VSGServiceInstance() self.user = User(email="*****@*****.**") self.tenant = VSGServiceInstance(id=1) self.flavor = Flavor(name="m1.small") self.npt_ctag = NetworkParameterType(name="c_tag", id=1) self.npt_stag = NetworkParameterType(name="s_tag", id=2) self.npt_neutron_port_name = NetworkParameterType(name="neutron_port_name", id=3) self.node = Node(hostname="my.node.com") self.slice = Slice(name="mysite_test1", default_flavor=self.flavor, default_isolation="vm") self.priv_template = NetworkTemplate(name="access_network", visibility="private") self.priv_network = Network(name="mysite_test1_private", template=self.priv_template) self.image = Image(name="trusty-server-multi-nic") self.deployment = Deployment(name="testdeployment") Tag.objects.item_list = []
def setUp(self): global mock_enumerator, event_loop self.sys_path_save = sys.path self.cwd_save = os.getcwd() sys.path.append(xos_dir) sys.path.append(os.path.join(xos_dir, "synchronizers", "new_base")) sys.path.append( os.path.join(xos_dir, "synchronizers", "new_base", "tests", "steps")) config = os.path.join(test_path, "test_config.yaml") from xosconfig import Config Config.clear() Config.init(config, "synchronizer-config-schema.yaml") from synchronizers.new_base.mock_modelaccessor_build import ( build_mock_modelaccessor, ) build_mock_modelaccessor(xos_dir, services_dir=None, service_xprotos=[]) os.chdir(os.path.join(test_path, "..")) # config references tests/model-deps import event_loop reload(event_loop) import backend reload(backend) from mock_modelaccessor import mock_enumerator from modelaccessor import model_accessor # import all class names to globals for (k, v) in model_accessor.all_model_classes.items(): globals()[k] = v # self.policy = TenantWithContainerPolicy() # self.user = User(email="*****@*****.**") # self.tenant = Tenant(creator=self.user) # self.flavor = Flavor(name="m1.small") # model_policy_tenantwithcontainer.Instance = Instance # model_policy_tenantwithcontainer.Flavor = Flavor b = backend.Backend() steps_dir = Config.get("steps_dir") self.steps = b.load_sync_step_modules(steps_dir) self.synchronizer = event_loop.XOSObserver(self.steps)
def setUp(self): config = os.path.abspath( os.path.dirname(os.path.realpath(__file__)) + "/test_config.yaml") Config.clear() # in case left unclean by a previous test case Config.init(config) import backupprocessor self.backupprocessor = backupprocessor self.setUpPyfakefs() self.processor = backupprocessor.BackupProcessor() self.mock_backuphandler = MagicMock(backup=MagicMock(), restore=MagicMock())
def setUp(self): global DeferredException self.sys_path_save = sys.path # Setting up the config module from xosconfig import Config config = os.path.join(test_path, "../test_fabric_crossconnect_config.yaml") Config.clear() Config.init(config, "synchronizer-config-schema.yaml") # END Setting up the config module from xossynchronizer.mock_modelaccessor_build import mock_modelaccessor_config mock_modelaccessor_config(test_path, [ ("fabric-crossconnect", "fabric-crossconnect.xproto"), ]) import xossynchronizer.modelaccessor import mock_modelaccessor reload( mock_modelaccessor) # in case nose2 loaded it in a previous test reload(xossynchronizer.modelaccessor ) # in case nose2 loaded it in a previous test from xossynchronizer.modelaccessor import model_accessor self.model_accessor = model_accessor from sync_fabric_crossconnect_service_instance import SyncFabricCrossconnectServiceInstance, model_accessor, \ DeferredException from helpers import Helpers self.helpers = Helpers # import all class names to globals for (k, v) in model_accessor.all_model_classes.items(): globals()[k] = v self.sync_step = SyncFabricCrossconnectServiceInstance self.sync_step.log = Mock() # mock onos-fabric self.onos_fabric = Service(name="onos-fabric", rest_hostname="onos-fabric", rest_port="8181", rest_username="******", rest_password="******") self.service = FabricCrossconnectService( name="fcservice", provider_services=[self.onos_fabric])
def setUp(self): global dynamicbuild config = basic_conf = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + "/test_config.yaml") Config.clear() # in case left unclean by a previous test case Config.init(config) import dynamicbuild self.base_dir = tempfile.mkdtemp() self.example_xproto = """option app_label = "exampleservice"; option name = "exampleservice"; message ExampleService (Service){ option verbose_name = "Example Service"; required string service_message = 1 [help_text = "Service Message to Display", max_length = 254, null = False, db_index = False, blank = False]; } message Color (XOSBase){ option verbose_name = "Color"; required string name = 1 [help_text = "Name for this color", db_index = False, max_length = 256, null = False, blank = False]; required string html_code = 2 [help_text = "Code for this color", db_index = False, max_length = 256, null = False, blank = False]; } message ExampleServiceInstance (TenantWithContainer){ option verbose_name = "Example Service Instance"; required string tenant_message = 1 [help_text = "Tenant Message to Display", max_length = 254, null = False, db_index = False, blank = False]; optional manytoone foreground_color->Color:serviceinstance_foreground_colors = 3 [db_index = True, null = True, blank = True]; optional manytoone background_color->Color:serviceinstance_background_colors = 3 [db_index = True, null = True, blank = True]; } message EmbeddedImage (XOSBase){ option verbose_name = "Embedded Image"; required string name = 1 [help_text = "Name for this image", db_index = False, max_length = 256, null = False, blank = False]; required string url = 2 [help_text = "URL for this image", db_index = False, max_length = 256, null = False, blank = False]; optional manytoone serviceinstance->ExampleServiceInstance:embedded_images = 3 [db_index = True, null = True, blank = True]; } """ self.example_xproto_item = DynamicLoadItem(filename = "exampleservice.xproto", contents = self.example_xproto) self.example_request = DynamicLoadRequest(name = "exampleservice", version = "1", xprotos = [self.example_xproto_item]) self.example_unload_request = DynamicUnloadRequest(name = "exampleservice", version = "1") self.builder = dynamicbuild.DynamicBuilder(base_dir = self.base_dir)
def setUpClass(cls): global log config = os.path.join(test_path, "test_config.yaml") from xosconfig import Config Config.clear() Config.init(config, "synchronizer-config-schema.yaml") if not log: from multistructlog import create_logger log = create_logger(Config().get("logging"))
def setUp(self): self.sys_path_save = sys.path # Setting up the config module from xosconfig import Config config = os.path.join(test_path, "../test_config.yaml") Config.clear() Config.init(config, "synchronizer-config-schema.yaml") # END Setting up the config module from xossynchronizer.mock_modelaccessor_build import build_mock_modelaccessor # Can't use mock_modelaccessor_config because we're not in the xos-services directory, so do it # the long way... xos_dir = os.path.join(test_path, "../../../../xos") services_dir = os.path.join(test_path, "../../../..") service_xprotos = [ os.path.join(test_path, "../models/testservice.xproto") ] build_mock_modelaccessor(None, xos_dir, services_dir, service_xprotos) # mock_modelaccessor_config(test_path, [("testservice", "testservice.xproto")]) import xossynchronizer.modelaccessor import mock_modelaccessor imp.reload( mock_modelaccessor) # in case nose2 loaded it in a previous test imp.reload(xossynchronizer.modelaccessor ) # in case nose2 loaded it in a previous test from model_policy_testservice_serviceinstance import TestserviceServiceInstancePolicy from xossynchronizer.modelaccessor import model_accessor self.model_accessor = model_accessor # import all class names to globals for (k, v) in model_accessor.all_model_classes.items(): globals()[k] = v # Some of the functions we call have side-effects, reset the world. model_accessor.reset_all_object_stores() self.policy = TestserviceServiceInstancePolicy(self.model_accessor) self.si = Mock(sync_after_policy=False, sync_during_policy=False, policy_after_sync=False, policy_during_sync=False, update_during_sync=False, update_during_policy=False, create_duplicate=False)
def setUp(self): self.sys_path_save = sys.path self.cwd_save = os.getcwd() sys.path.append(xos_dir) sys.path.append(os.path.join(xos_dir, "synchronizers", "new_base")) sys.path.append( os.path.join(xos_dir, "synchronizers", "new_base", "tests", "steps")) config = os.path.join(test_path, "test_config.yaml") from xosconfig import Config Config.clear() Config.init(config, "synchronizer-config-schema.yaml") from synchronizers.new_base.mock_modelaccessor_build import ( build_mock_modelaccessor, ) build_mock_modelaccessor(xos_dir, services_dir=None, service_xprotos=[]) os.chdir(os.path.join(test_path, "..")) # config references tests/model-deps import event_loop reload(event_loop) import backend reload(backend) from modelaccessor import model_accessor # import all class names to globals for (k, v) in model_accessor.all_model_classes.items(): globals()[k] = v b = backend.Backend() steps_dir = Config.get("steps_dir") self.steps = b.load_sync_step_modules(steps_dir) self.synchronizer = event_loop.XOSObserver(self.steps) try: os.remove("/tmp/sync_ports") except OSError: pass try: os.remove("/tmp/delete_ports") except OSError: pass
def setUp(self): global TenantWithContainerPolicy, LeastLoadedNodeScheduler, MockObjectList self.sys_path_save = sys.path self.cwd_save = os.getcwd() sys.path.append(xos_dir) sys.path.append(os.path.join(xos_dir, "synchronizers", "new_base")) sys.path.append( os.path.join(xos_dir, "synchronizers", "new_base", "model_policies")) config = basic_conf = os.path.abspath( os.path.dirname(os.path.realpath(__file__)) + "/test_config.yaml") Config.clear() # in case left unclean by a previous test case Config.init(config, "synchronizer-config-schema.yaml") from synchronizers.new_base.mock_modelaccessor_build import ( build_mock_modelaccessor, ) build_mock_modelaccessor(xos_dir, services_dir=None, service_xprotos=[]) import model_policy_tenantwithcontainer from model_policy_tenantwithcontainer import ( TenantWithContainerPolicy, LeastLoadedNodeScheduler, ) from mock_modelaccessor import MockObjectList # import all class names to globals for ( k, v, ) in model_policy_tenantwithcontainer.model_accessor.all_model_classes.items( ): globals()[k] = v # TODO: Mock_model_accessor lacks save or delete methods # Instance.save = mock.Mock # Instance.delete = mock.Mock # TenantWithContainer.save = mock.Mock self.policy = TenantWithContainerPolicy() self.user = User(email="*****@*****.**") self.tenant = TenantWithContainer(creator=self.user) self.flavor = Flavor(name="m1.small")
def setUp(self): self.sys_path_save = sys.path self.cwd_save = os.getcwd() config = os.path.join(test_path, "test_config.yaml") from xosconfig import Config Config.clear() Config.init(config, "synchronizer-config-schema.yaml") from xossynchronizer.mock_modelaccessor_build import build_mock_modelaccessor build_mock_modelaccessor( sync_lib_dir, xos_dir, services_dir=None, service_xprotos=[] ) os.chdir( os.path.join(test_path, "..") ) # config references xos-synchronizer-tests/model-deps import xossynchronizer.event_loop reload(xossynchronizer.event_loop) import xossynchronizer.backend reload(xossynchronizer.backend) from xossynchronizer.modelaccessor import model_accessor # import all class names to globals for (k, v) in model_accessor.all_model_classes.items(): globals()[k] = v from xossynchronizer.modelaccessor import model_accessor b = xossynchronizer.backend.Backend(model_accessor=model_accessor) steps_dir = Config.get("steps_dir") self.steps = b.load_sync_step_modules(steps_dir) self.synchronizer = xossynchronizer.event_loop.XOSObserver( self.steps, model_accessor ) try: os.remove("/tmp/sync_ports") except OSError: pass try: os.remove("/tmp/delete_ports") except OSError: pass
def setUp(self): self.sys_path_save = sys.path # Setting up the config module from xosconfig import Config config = os.path.join(test_path, "../test_config.yaml") Config.clear() Config.init(config, "synchronizer-config-schema.yaml") # END Setting up the config module from xossynchronizer.mock_modelaccessor_build import build_mock_modelaccessor # Can't use mock_modelaccessor_config because we're not in the xos-services directory, so do it # the long way... xos_dir = os.path.join(test_path, "../../../../xos") services_dir = os.path.join(test_path, "../../../..") service_xprotos = [os.path.join(test_path, "../models/testservice.xproto")] build_mock_modelaccessor(None, xos_dir, services_dir, service_xprotos) import xossynchronizer.modelaccessor import mock_modelaccessor imp.reload(mock_modelaccessor) # in case nose2 loaded it in a previous test imp.reload(xossynchronizer.modelaccessor) # in case nose2 loaded it in a previous test from sync_testservice_serviceinstance import SyncTestserviceServiceInstance from xossynchronizer.modelaccessor import model_accessor self.model_accessor = model_accessor # import all class names to globals for (k, v) in model_accessor.all_model_classes.items(): globals()[k] = v self.sync_step = SyncTestserviceServiceInstance # TODO: Use modelaccessor instead # create a mock instance instance self.model = Mock(name="Example", some_integer=0, sync_after_policy=False, sync_during_policy=False, policy_after_sync=False, policy_during_sync=False, update_during_sync=False, update_during_policy=False, create_duplicate=False)
def setup_sync_unit_test(test_path, globals_dict, models, config_fn="test_config.yaml"): """ Perform the common steps associated with setting up a synchronizer unit test. 1) Import xosconfig.Config and set it up to test_config.yaml in the current dir 2) Build the mock modelaccessor and import it 3) Import all model accessor classes into global space Arguments: test_path - path to the test case that is being run globals_dict - a dictionary to add global models to models - a list of pairs (service_name, xproto_name) config_fn - filename of config file) Returns: Dictionary containing the following: sys_path_save: the original sys.path model_accessor: model accessor class Config: the Config object xos_dir: xos directory services_dir: services directory """ sys_path_save = sys.path # Setting up the config module from xosconfig import Config config = os.path.join(test_path, config_fn) Config.clear() Config.init(config, "synchronizer-config-schema.yaml") from xossynchronizer.mock_modelaccessor_build import mock_modelaccessor_config mock_modelaccessor_config(test_path, models) import xossynchronizer.modelaccessor reload(xossynchronizer.modelaccessor) # in case nose2 loaded it in a previous testp from xossynchronizer.modelaccessor import model_accessor # modelaccessor.py will have ensure mock_modelaccessor is in sys.path from mock_modelaccessor import MockObjectList # import all class names to globals for (k, v) in model_accessor.all_model_classes.items(): globals_dict[k] = v return {"sys_path_save": sys_path_save, "model_accessor": model_accessor, "Config": Config, "MockObjectList": MockObjectList}
def setUp(self): global DeferredException self.sys_path_save = sys.path # Setting up the config module from xosconfig import Config config = os.path.join(test_path, "../test_config.yaml") Config.clear() Config.init(config, "synchronizer-config-schema.yaml") # END Setting up the config module from xossynchronizer.mock_modelaccessor_build import mock_modelaccessor_config mock_modelaccessor_config(test_path, [("fabric", "fabric.xproto")]) import xossynchronizer.modelaccessor import mock_modelaccessor imp.reload(mock_modelaccessor) # in case nose2 loaded it in a previous test imp.reload(xossynchronizer.modelaccessor) # in case nose2 loaded it in a previous test from xossynchronizer.modelaccessor import model_accessor self.model_accessor = model_accessor from sync_fabric_port import SyncFabricPort # import all class names to globals for (k, v) in model_accessor.all_model_classes.items(): globals()[k] = v self.sync_step = SyncFabricPort self.sync_step.log = Mock() # mock onos-fabric onos_fabric = Mock() onos_fabric.name = "onos-fabric" onos_fabric.rest_hostname = "onos-fabric" onos_fabric.rest_port = "8181" onos_fabric.rest_username = "******" onos_fabric.rest_password = "******" onos_fabric_base = Mock() onos_fabric_base.leaf_model = onos_fabric self.fabric = Mock() self.fabric.name = "fabric" self.fabric.provider_services = [onos_fabric_base]
def setUp(self): self.sys_path_save = sys.path # Setting up the config module from xosconfig import Config config = os.path.join(test_path, "../test_config.yaml") Config.clear() Config.init(config, "synchronizer-config-schema.yaml") # END Setting up the config module from xossynchronizer.mock_modelaccessor_build import build_mock_modelaccessor # Can't use mock_modelaccessor_config because we're not in the xos-services directory, so do it # the long way... xos_dir = os.path.join(test_path, "../../../../xos") services_dir = os.path.join(test_path, "../../../..") service_xprotos = [os.path.join(test_path, "../models/testservice.xproto")] build_mock_modelaccessor(None, xos_dir, services_dir, service_xprotos) # mock_modelaccessor_config(test_path, [("testservice", "testservice.xproto")]) import xossynchronizer.modelaccessor import mock_modelaccessor imp.reload(mock_modelaccessor) # in case nose2 loaded it in a previous test imp.reload(xossynchronizer.modelaccessor) # in case nose2 loaded it in a previous test from model_policy_testservice_serviceinstance import TestserviceServiceInstancePolicy from xossynchronizer.modelaccessor import model_accessor self.model_accessor = model_accessor # import all class names to globals for (k, v) in model_accessor.all_model_classes.items(): globals()[k] = v # Some of the functions we call have side-effects, reset the world. model_accessor.reset_all_object_stores() self.policy = TestserviceServiceInstancePolicy(self.model_accessor) self.si = Mock(sync_after_policy=False, sync_during_policy=False, policy_after_sync=False, policy_during_sync=False, update_during_sync=False, update_during_policy=False, create_duplicate=False)
def setUp(self): self.sys_path_save = sys.path self.cwd_save = os.getcwd() config = os.path.join(test_path, "test_config.yaml") from xosconfig import Config Config.clear() Config.init(config, "synchronizer-config-schema.yaml") from xossynchronizer import loadmodels from xossynchronizer.loadmodels import ModelLoadClient self.loadmodels = loadmodels self.api = MagicMock() self.api.dynamicload_pb2.LoadModelsRequest = MockLoadModelsRequest self.loader = ModelLoadClient(self.api)
def setUp(self): global DeferredException self.sys_path_save = sys.path # Setting up the config module from xosconfig import Config config = os.path.join(test_path, "../test_config.yaml") Config.clear() Config.init(config, "synchronizer-config-schema.yaml") # END Setting up the config module from xossynchronizer.mock_modelaccessor_build import mock_modelaccessor_config mock_modelaccessor_config(test_path, [("fabric", "fabric.xproto"), ("onos-service", "onos.xproto")]) import xossynchronizer.modelaccessor import mock_modelaccessor imp.reload(mock_modelaccessor) # in case nose2 loaded it in a previous test imp.reload(xossynchronizer.modelaccessor) # in case nose2 loaded it in a previous test from xossynchronizer.modelaccessor import model_accessor self.model_accessor = model_accessor from mock_modelaccessor import MockObjectList from kubernetes_event import KubernetesPodDetailsEventStep # import all class names to globals for (k, v) in model_accessor.all_model_classes.items(): globals()[k] = v self.event_step = KubernetesPodDetailsEventStep self.onos = ONOSService(name="myonos", id=1111, rest_hostname="onos-url", rest_port="8181", rest_username="******", rest_password="******", backend_code=1, backend_status="succeeded") self.fabric_service = FabricService(name="fabric", id=1112, backend_code=1, backend_status="succeeded", provider_services=[self.onos]) self.switch = Switch(name="switch1", backend_code=1, backend_status="succeeded") self.port1 = SwitchPort(name="switch1port1", switch=self.switch, backend_code=1, backend_status="succeeded") self.port2 = SwitchPort(name="switch1port2", switch=self.switch, backend_code=1, backend_status="succeeded") self.switch.ports = MockObjectList([self.port1, self.port2]) self.log = Mock()
def setUp(self): global DeferredException self.sys_path_save = sys.path # Setting up the config module from xosconfig import Config config = os.path.join(test_path, "../test_config.yaml") Config.clear() Config.init(config, "synchronizer-config-schema.yaml") # END Setting up the config module # Mock the kafka producer self.mockxoskafka = MagicMock() modules = { 'xoskafka': self.mockxoskafka, 'xoskafka.XOSKafkaProducer': self.mockxoskafka.XOSKafkaProducer, } self.module_patcher = patch.dict('sys.modules', modules) self.module_patcher.start() from xossynchronizer.mock_modelaccessor_build import mock_modelaccessor_config mock_modelaccessor_config(test_path, [("fabric", "fabric.xproto"), ("onos-service", "onos.xproto")]) import xossynchronizer.modelaccessor import mock_modelaccessor imp.reload(mock_modelaccessor) # in case nose2 loaded it in a previous test imp.reload(xossynchronizer.modelaccessor) # in case nose2 loaded it in a previous test from xossynchronizer.modelaccessor import model_accessor self.model_accessor = model_accessor from mock_modelaccessor import MockObjectList # necessary to reset XOSKafkaProducer's call_count import onos_event reload(onos_event) from onos_event import OnosPortEventStep, XOSKafkaProducer self.XOSKafkaProducer = XOSKafkaProducer # import all class names to globals for (k, v) in model_accessor.all_model_classes.items(): globals()[k] = v self.event_step = OnosPortEventStep self.fabric_service = FabricService(name="fabric", id=1112, backend_code=1, backend_status="succeeded") self.switch = Switch(name="switch1", ofId="of:0000000000000001", backend_code=1, backend_status="succeeded") self.port1 = SwitchPort(name="switch1port1", switch=self.switch, switch_id=self.switch.id, portId="1", oper_status=None, backend_code=1, backend_status="succeeded") self.port2 = SwitchPort(name="switch1port2", kind="access", switch=self.switch, switch_id=self.switch.id, portId="2", oper_status=None, backend_code=1, backend_status="succeeded") self.switch.ports = MockObjectList([self.port1, self.port2]) self.log = Mock()
def tearDown(self): # NOTE clear the config after each test Config.clear()
def setUp(self): # In case some other testcase in nose has left config in an unclean state Config.clear()
def setUp(self): global SyncVSGServiceInstance, LeastLoadedNodeScheduler, MockObjectList self.sys_path_save = sys.path sys.path.append(xos_dir) sys.path.append(os.path.join(xos_dir, 'synchronizers', 'new_base')) config = os.path.join(test_path, "test_config.yaml") from xosconfig import Config Config.clear() Config.init(config, 'synchronizer-config-schema.yaml') from synchronizers.new_base.mock_modelaccessor_build import build_mock_modelaccessor build_mock_modelaccessor(xos_dir, services_dir, [get_models_fn("vsg", "vsg.xproto"), get_models_fn("addressmanager", "addressmanager.xproto")]) import synchronizers.new_base.modelaccessor import synchronizers.new_base.model_policies.model_policy_tenantwithcontainer import sync_vsgserviceinstance from sync_vsgserviceinstance import SyncVSGServiceInstance, model_accessor from mock_modelaccessor import MockObjectList # import all class names to globals for (k, v) in model_accessor.all_model_classes.items(): globals()[k] = v # Some of the functions we call have side-effects. For example, creating a VSGServiceInstance may lead to creation of # tags. Ideally, this wouldn't happen, but it does. So make sure we reset the world. model_accessor.reset_all_object_stores() # attic functions that are not present in the mock model accessor AddressManagerServiceInstance.set_attribute = Mock() self.syncstep = SyncVSGServiceInstance() # set up an object hierarchy that represents a Service and ServiceInstance self.user = User(email="*****@*****.**") self.service = VSGService(name="the_vsg_service", id=1, docker_image_name="reg/vsg_docker", docker_insecure_registry=True, dns_servers="dnsone,dnstwo", url_filter_kind=None, private_key_fn=os.path.join(test_path, "test_private_key")) self.subscriber = MagicMock(firewall_rules = "rule1", firewall_enable = True, url_filter_enable = True, url_filter_level="R", cdn_enable=True, uplink_speed=1234, downlink_speed=5678, enable_uverse=False, status="suspended", sync_attributes=["firewall_rules", "firewall_enable", "url_filter_enable", "url_filter_level", "cdn_enable", "uplink_speed", "downlink_speed", "enable_uverse", "status"]) self.volt = MagicMock(s_tag=111, c_tag=222, subscriber=self.subscriber) self.tenant = VSGServiceInstance(id=401, volt=self.volt, owner=self.service, wan_container_ip="10.7.1.3", wan_container_netbits="24", wan_container_mac="02:42:0a:07:01:03", wan_container_gateway_ip="10.7.1.1", wan_vm_ip="10.7.1.2", wan_vm_mac="02:42:0a:07:01:02", sync_attributes = ["wan_container_ip", "wan_container_netbits", "wan_container_mac", "wan_container_gateway_ip", "wan_vm_ip", "wan_vm_mac"]) self.flavor = Flavor(name="m1.small") self.npt_ctag = NetworkParameterType(name="c_tag", id=1) self.npt_stag = NetworkParameterType(name="s_tag", id=2) self.npt_neutron_port_name = NetworkParameterType(name="neutron_port_name", id=501) self.priv_template = NetworkTemplate(name="access_network", visibility="private") self.priv_network = Network(name="mysite_test1_private", template=self.priv_template) self.image = Image(name="trusty-server-multi-nic") self.deployment = Deployment(name="testdeployment") self.user = User(email="smbaker", id=701) self.controller = Controller(id=101) self.node = Node(name="testnode") self.slice = Slice(name="mysite_test1", default_flavor=self.flavor, default_isolation="vm", service=self.service, id=301) self.instance = Instance(slice=self.slice, instance_name="testinstance1_instance_name", instance_id="testinstance1_instance_id", name="testinstance1_name", node=self.node, creator=self.user, controller=self.controller) self.tenant.instance = self.instance self.instance.get_ssh_ip = Mock(return_value="1.2.3.4") self.controllerslice = ControllerSlice(slice_id=self.slice.id, controller_id=self.controller.id, id=201) self.controlleruser = ControllerUser(user_id=self.user.id, controller_id=self.controller.id, id=601)
def setUp(self): global DeferredException self.sys_path_save = sys.path # Setting up the config module from xosconfig import Config config = os.path.join(test_path, "../test_config.yaml") Config.clear() Config.init(config, "synchronizer-config-schema.yaml") # END Setting up the config module from xossynchronizer.mock_modelaccessor_build import mock_modelaccessor_config mock_modelaccessor_config(test_path, [("onos-service", "onos.xproto"), ]) import xossynchronizer.modelaccessor import mock_modelaccessor reload(mock_modelaccessor) # in case nose2 loaded it in a previous test reload(xossynchronizer.modelaccessor) # in case nose2 loaded it in a previous test from xossynchronizer.modelaccessor import model_accessor self.model_accessor = model_accessor from mock_modelaccessor import MockObjectList from kubernetes_event import KubernetesPodDetailsEventStep # import all class names to globals for (k, v) in model_accessor.all_model_classes.items(): globals()[k] = v self.event_step = KubernetesPodDetailsEventStep self.onos = ONOSService(name="myonos", rest_hostname="onos-url", rest_port="8181", rest_username="******", rest_password="******", backend_code=1, backend_status="succeeded") self.attr = ServiceInstanceAttribute( name="foo", value="bar" ) self.mockAllAttr = Mock() self.mockAllAttr.all.return_value = [self.attr] self.app1 = ONOSApp(name="myapp1", owner=self.onos, backend_code=1, backend_status="succeeded", service_instance_attributes=self.mockAllAttr) self.app2 = ONOSApp(name="myapp2", owner=self.onos, backend_code=1, backend_status="succeeded", service_instance_attributes=self.mockAllAttr) self.onos.service_instances = MockObjectList([self.app1, self.app2]) self.log = Mock()
def setUp(self): self.sys_path_save = sys.path # Setting up the config module from xosconfig import Config config = os.path.join(test_path, "../test_config.yaml") Config.clear() Config.init(config, "synchronizer-config-schema.yaml") # END Setting up the config module from xossynchronizer.mock_modelaccessor_build import mock_modelaccessor_config mock_modelaccessor_config(test_path, [("onos-service", "onos.xproto"), ]) import xossynchronizer.modelaccessor import mock_modelaccessor reload(mock_modelaccessor) # in case nose2 loaded it in a previous test reload(xossynchronizer.modelaccessor) # in case nose2 loaded it in a previous test from sync_onos_service import SyncONOSService, model_accessor self.model_accessor = model_accessor # import all class names to globals for (k, v) in model_accessor.all_model_classes.items(): globals()[k] = v self.sync_step = SyncONOSService self.onos = Mock(spec=[ 'id', 'name', "rest_hostname", "rest_port", "rest_username", "rest_password", "class_names" ]) self.onos.id = 1 self.onos.name = "onos" self.onos.rest_hostname = "onos-url" self.onos.rest_port = "8181" self.onos.rest_username = "******" self.onos.rest_password = "******" self.onos.class_names = "ONOSService" self.service = Mock() self.service.id = 1 self.service.serviceattribute_dict = {} self.service.leaf_model = self.onos self.onos_service_attribute = Mock(spec=[ 'id', 'service', 'name', 'value' ]) self.onos_service_attribute.service = self.service self.onos_service_attribute.name = "/onos/v1/network/configuration/apps/org.opencord.olt" self.onos_service_attribute.value = { "kafka": { "bootstrapServers": "cord-kafka-kafka.default.svc.cluster.local:9092" } }
def setUp(self): global dynamicbuild config = os.path.abspath( os.path.dirname(os.path.realpath(__file__)) + "/test_config.yaml" ) Config.clear() # in case left unclean by a previous test case Config.init(config) import dynamicbuild self.base_dir = tempfile.mkdtemp() self.example_xproto = """option app_label = "exampleservice"; option name = "exampleservice"; message ExampleService (Service){ option verbose_name = "Example Service"; required string service_message = 1 [help_text = "Service Message to Display", max_length = 254, null = False, db_index = False, blank = False]; } message Color (XOSBase){ option verbose_name = "Color"; required string name = 1 [help_text = "Name for this color", db_index = False, max_length = 256, null = False, blank = False]; required string html_code = 2 [help_text = "Code for this color", db_index = False, max_length = 256, null = False, blank = False]; } message ExampleServiceInstance (TenantWithContainer){ option verbose_name = "Example Service Instance"; required string tenant_message = 1 [help_text = "Tenant Message to Display", max_length = 254, null = False, db_index = False, blank = False]; optional manytoone foreground_color->Color:serviceinstance_foreground_colors = 3 [db_index = True, null = True, blank = True]; optional manytoone background_color->Color:serviceinstance_background_colors = 3 [db_index = True, null = True, blank = True]; } message EmbeddedImage (XOSBase){ option verbose_name = "Embedded Image"; required string name = 1 [help_text = "Name for this image", db_index = False, max_length = 256, null = False, blank = False]; required string url = 2 [help_text = "URL for this image", db_index = False, max_length = 256, null = False, blank = False]; optional manytoone serviceinstance->ExampleServiceInstance:embedded_images = 3 [db_index = True, null = True, blank = True]; } """ self.example_xproto_item = DynamicLoadItem( filename="exampleservice.xproto", contents=self.example_xproto ) self.example_request = DynamicLoadRequest( name="exampleservice", version="1", xprotos=[self.example_xproto_item], convenience_methods=[], ) self.example_unload_request = DynamicUnloadRequest( name="exampleservice", version="1" ) self.builder = dynamicbuild.DynamicBuilder(base_dir=self.base_dir)