Beispiel #1
0
 def _test_get_child_level(self):
     """
     [XOS-Config] Should return a child level param
     """
     Config.init(sample_conf)
     res = Config.get("nested.parameter.for")
     self.assertEqual(res, "testing")
Beispiel #2
0
 def test_missing_file_exception(self):
     """
     [XOS-Config] Raise if file not found 
     """
     with self.assertRaises(Exception) as e:
         Config.init("missing_conf")
     self.assertEqual(e.exception.message, "[XOS-Config] Config file not found at: missing_conf")
Beispiel #3
0
 def test_invalid_format(self):
     """
     [XOS-Config] Raise if format is not valid (we expect a dictionary)
     """
     with self.assertRaises(Exception) as e:
         Config.init(invalid_format)
     self.assertEqual(e.exception.message, "[XOS-Config] The config format is wrong: Schema validation failed:\n - Value '['I am', 'a yaml', 'but the', 'format is not', 'correct']' is not a dict. Value path: ''.")
Beispiel #4
0
    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 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()
Beispiel #6
0
    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()
Beispiel #7
0
 def test_get_default_val_for_missing_param(self):
     """
     [XOS-Config] Should get the default value if nothing is specified
     """
     Config.init(basic_conf)
     dir = Config.get("xos_dir")
     self.assertEqual(dir, "/opt/xos")
Beispiel #8
0
 def test_get_config_file(self):
     """
     [XOS-Config] Should return the config file in use
     """
     Config.init(sample_conf)
     res = Config.get_config_file()
     self.assertEqual(res, sample_conf)
Beispiel #9
0
 def test_get_missing_param(self):
     """
     [XOS-Config] Should return None reading a missing param
     """
     Config.init(sample_conf)
     res = Config.get("foo")
     self.assertEqual(res, None)
Beispiel #10
0
 def test_yaml_not_valid(self):
     """
     [XOS-Config] Raise if yaml is not valid
     """
     with self.assertRaises(Exception) as e:
         Config.init(yaml_not_valid)
     self.assertEqual(e.exception.message, "[XOS-Config] The config format is wrong: Unable to load any data from source yaml file")
Beispiel #11
0
 def test_get_child_level(self):
     """
     [XOS-Config] Should return a child level param
     """
     Config.init(sample_conf)
     res = Config.get("database.name")
     self.assertEqual(res, "xos")
Beispiel #12
0
 def test_initialize_only_once(self):
     """
     [XOS-Config] Raise if initialized twice
     """
     with self.assertRaises(Exception) as e:
         Config.init(sample_conf)
         Config2.init(sample_conf)
     self.assertEqual(str(e.exception), "[XOS-Config] Module already initialized")
Beispiel #13
0
 def test_schema_override_usage(self):
     """
     [XOS-Config] the XOS_CONFIG_SCHEMA should be used to validate a config
     """
     os.environ["XOS_CONFIG_SCHEMA"] = small_schema
     with self.assertRaises(Exception) as e:
         Config.init(basic_conf)
     self.assertEqual(e.exception.message, "[XOS-Config] The config format is wrong: Schema validation failed:\n - Key 'database' was not defined. Path: ''.")
     del os.environ["XOS_CONFIG_SCHEMA"]
Beispiel #14
0
 def test_config_override(self):
     """
     [XOS-Config] If an override is provided for the config, it should return the overridden value
     """
     Config.init(sample_conf, "xos-config-schema.yaml", override_conf)
     res = Config.get("logging.level")
     self.assertEqual(res, "info")
     res = Config.get("database.password")
     self.assertEqual(res, "overridden_password")
Beispiel #15
0
 def test_yaml_not_valid(self):
     """
     [XOS-Config] Raise if yaml is not valid
     """
     with self.assertRaises(Exception) as e:
         Config.init(yaml_not_valid)
     self.assertTrue(
         str(e.exception).startswith("[XOS-Config] The config format is wrong:")
     )
Beispiel #16
0
 def test_get_first_level(self):
     """
     [XOS-Config] Should return a first level param
     """
     Config.init(sample_conf)
     # NOTE we are using Config2 here to be sure that the configuration is readable from any import,
     # not only from the one that has been used to initialize it
     res = Config2.get("database")
     self.assertEqual(res, {"name": "xos", "username": "******", "password": "******"})
Beispiel #17
0
 def test_env_override(self):
     """
     [XOS-Config] the XOS_CONFIG_FILE environment variable should override the config_file
     """
     os.environ["XOS_CONFIG_FILE"] = "env.yaml"
     with self.assertRaises(Exception) as e:
         Config.init("missing_conf")
     self.assertEqual(e.exception.message, "[XOS-Config] Config file not found at: env.yaml")
     del os.environ["XOS_CONFIG_FILE"]
Beispiel #18
0
 def test_schema_override(self):
     """
     [XOS-Config] the XOS_CONFIG_SCHEMA environment variable should override the config_schema
     """
     os.environ["XOS_CONFIG_SCHEMA"] = "env-schema.yaml"
     with self.assertRaises(Exception) as e:
         Config.init(basic_conf)
     self.assertRegexpMatches(e.exception.message, '\[XOS\-Config\] Config schema not found at: (.+)env-schema\.yaml')
     # self.assertEqual(e.exception.message, "[XOS-Config] Config schema not found at: env-schema.yaml")
     del os.environ["XOS_CONFIG_SCHEMA"]
Beispiel #19
0
    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)
Beispiel #20
0
def configure_logging(verbose):
    global log
    # INITIALIZING LOGGER
    Config.init()

    cfg = Config().get("logging")
    if verbose:
        cfg["handlers"]["console"]["level"] = "DEBUG"

    log = create_logger(cfg)
Beispiel #21
0
    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 = {}
Beispiel #22
0
    def test_config_extend(self):
        """
        [XOS-Config] If an override is provided for the config, it should
        return the overridden value (also if not defined in the base one)
        """

        Config.init(sample_conf, "xos-config-schema.yaml", extend_conf)
        res = Config.get("xos_dir")
        self.assertEqual(res, "/opt/xos")
        res = Config.get("database.password")
        self.assertEqual(res, "safe")
Beispiel #23
0
 def test_get_default_val_for_missing_param(self):
     """
     [XOS-Config] Should get the default value if nothing is specified
     """
     Config.init(basic_conf)
     log = Config.get("logging")
     self.assertEqual(log, {
         "level": "info",
         "channels": ["file", "console"],
         "logstash_hostport": "cordloghost:5617",
         "file":  "/var/log/xos.log",
     })
def main():
    base_config_file = os.path.abspath(os.path.dirname(
        os.path.realpath(__file__)) + '/config.yaml')
    mounted_config_file = os.path.abspath(os.path.dirname(
        os.path.realpath(__file__)) + '/mounted_config.yaml')

    if os.path.isfile(mounted_config_file):
        Config.init(base_config_file, 'synchronizer-config-schema.yaml',
                    mounted_config_file)
    else:
        Config.init(base_config_file, 'synchronizer-config-schema.yaml')

    Synchronizer().run()
    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 = []
Beispiel #26
0
    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
Beispiel #27
0
def main():
    input_fn = sys.argv[1]
    result_fn = sys.argv[2]

    args = pickle.loads(open(input_fn).read())

    Config.init(args['config_file'], 'synchronizer-config-schema.yaml')

    ansible_hosts = args["ansible_hosts"]
    ansible_config = args["ansible_config"]
    fqp = args["fqp"]
    opts = args["opts"]

    result = run_playbook(ansible_hosts, ansible_config, fqp, opts)

    open(result_fn, "w").write(pickle.dumps(result))
Beispiel #28
0
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):

        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(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)
Beispiel #31
0
    def setUp(self):
        global mock_enumerator, event_loop

        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

        event_loop = xossynchronizer.event_loop

        reload(xossynchronizer.event_loop)
        import xossynchronizer.backend

        reload(xossynchronizer.backend)
        from xossynchronizer.modelaccessor import model_accessor
        from mock_modelaccessor import mock_enumerator

        # 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 mock_modelaccessor_config
        mock_modelaccessor_config(test_path, [("att-workflow-driver", "att-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',
            'serial_number': 'BRCM1234',
            'of_dpid': 'of:109299321',
            'uni_port_id': 16
        }
        self.event.value = json.dumps(self.event_dict)

        self.att = AttWorkflowDriverService(name="att-workflow-driver")
Beispiel #33
0
    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")
        from multistructlog import create_logger
        log = create_logger(Config().get('logging'))
        # 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("olt-service", "volt.xproto")])

        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 auth_event import SubscriberAuthEventStep, model_accessor

        # import all class names to globals
        for (k, v) in model_accessor.all_model_classes.items():
            globals()[k] = v

        self.log = log

        self.event_step = SubscriberAuthEventStep(self.log)

        self.event = Mock()

        self.volt = Mock()
        self.volt.name = "vOLT"
        self.volt.leaf_model = Mock()

        self.hippie_si = HippieOSSServiceInstance()
        self.hippie_si.serial_number = "BRCM1234"
        self.hippie_si.save = Mock()
Beispiel #34
0
    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)

        # 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)
Beispiel #35
0
    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, [
            ("olt-service", "volt.xproto"),
            ("vsg", "vsg.xproto"),
            ("rcord", "rcord.xproto"),
        ])

        import xossynchronizer.modelaccessor
        reload(xossynchronizer.modelaccessor
               )  # in case nose2 loaded it in a previous test

        from xossynchronizer.modelaccessor import model_accessor
        self.model_accessor = model_accessor

        from xossynchronizer.steps.syncstep import DeferredException
        from sync_onu_device import SyncONUDevice, model_accessor

        # import all class names to globals
        for (k, v) in model_accessor.all_model_classes.items():
            globals()[k] = v

        self.sync_step = SyncONUDevice

        volt_service = Mock()
        volt_service.voltha_url = "voltha_url"
        volt_service.voltha_port = 1234
        volt_service.voltha_user = "******"
        volt_service.voltha_pass = "******"

        self.o = Mock()
        self.o.device_id = "test_id"
        self.o.pon_port.olt_device.volt_service = volt_service
    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

        # 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])
Beispiel #37
0
    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_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", "fabric.xproto")])
        import synchronizers.new_base.modelaccessor

        from sync_fabric_port import SyncFabricPort, model_accessor

        # 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]
Beispiel #38
0
    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, [("olt-service", "volt.xproto"),
                                              ("rcord", "rcord.xproto")])

        import xossynchronizer.modelaccessor
        reload(xossynchronizer.modelaccessor
               )  # in case nose2 loaded it in a previous test

        from xossynchronizer.modelaccessor import model_accessor
        self.model_accessor = model_accessor

        from xossynchronizer.modelaccessor import model_accessor
        from sync_onu_device import SyncONUDevice

        # import all class names to globals
        for (k, v) in model_accessor.all_model_classes.items():
            globals()[k] = v

        self.sync_step = SyncONUDevice

        volt_service = Mock()
        volt_service.voltha_url = MOCK_VOLTHA_SERVER_ADDRESS
        volt_service.voltha_port = MOCK_VOLTHA_SERVER_PORT

        self.o = Mock()
        self.o.device_id = "test_id"
        self.o.pon_port.olt_device.volt_service = volt_service

        clear_voltha_client_cache()
        self.server = grpc.server(ThreadPoolExecutor(max_workers=5))
        self.voltha_mock, _, _ = VolthaServerMock.start_voltha_server(
            self.server)
Beispiel #39
0
    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")
Beispiel #40
0
    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, [("att-workflow-driver", "att-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_att_workflow_driver_serviceinstance import AttWorkflowDriverServiceInstancePolicy, AttHelpers
        self.AttHelpers = AttHelpers

        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 = AttWorkflowDriverServiceInstancePolicy(
            model_accessor=model_accessor)
        self.si = AttWorkflowDriverServiceInstance()
        self.si.owner = AttWorkflowDriverService()
        self.si.serial_number = "BRCM1234"
Beispiel #41
0
    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):
        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"),
            ("vsg", "vsg.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 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 = VOLTServiceInstancePolicy(
            model_accessor=self.model_accessor)
        self.si = Mock()
Beispiel #43
0
    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")])
        import synchronizers.new_base.modelaccessor

        from mock_modelaccessor import MockObjectList
        self.MockObjectList = MockObjectList

        from model_policy_fabriccrossconnectserviceinstance import FabricCrossconnectServiceInstancePolicy, \
            model_accessor

        # import all class names to globals
        for (k, v) in model_accessor.all_model_classes.items():
            globals()[k] = v

        self.policy_step = FabricCrossconnectServiceInstancePolicy
        self.policy_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'))

        # 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
        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 sync_hippie_oss_service_instance import SyncOSSServiceInstance, model_accessor

        # import all class names to globals
        for (k, v) in model_accessor.all_model_classes.items():
            globals()[k] = v


        self.sync_step = SyncOSSServiceInstance

        self.oss = Mock()
        self.oss.name = "oss"
        self.oss.id = 5367

        # create a mock HippieOssServiceInstance instance
        self.o = Mock()
        self.o.serial_number = "BRCM1234"
        self.o.of_dpid = "of:109299321"
        self.o.owner.leaf_model = self.oss
        self.o.tologdict.return_value = {}
Beispiel #45
0
    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)
    def setUp(self):
        global TenantWithContainerPolicy, LeastLoadedNodeScheduler, MockObjectList

        self.sys_path_save = sys.path
        self.cwd_save = os.getcwd()

        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 xossynchronizer.mock_modelaccessor_build import (
            build_mock_modelaccessor,
        )

        build_mock_modelaccessor(sync_lib_dir, xos_dir, services_dir=None, service_xprotos=[])

        import xossynchronizer.model_policies.model_policy_tenantwithcontainer
        from xossynchronizer.model_policies.model_policy_tenantwithcontainer import (
            TenantWithContainerPolicy,
            LeastLoadedNodeScheduler,
        )

        from mock_modelaccessor import MockObjectList

        # import all class names to globals
        for (
            k,
            v,
        ) in xossynchronizer.model_policies.model_policy_tenantwithcontainer.model_accessor.all_model_classes.items():
            globals()[k] = v

        from xossynchronizer.modelaccessor import model_accessor

        self.policy = TenantWithContainerPolicy(model_accessor=model_accessor)
        self.user = User(email="*****@*****.**")
        self.tenant = TenantWithContainer(creator=self.user)
        self.flavor = Flavor(name="m1.small")
Beispiel #47
0
    def setUp(self):
        global log, steps, 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)
        import steps.sync_instances
        import steps.sync_controller_slices
        from modelaccessor import model_accessor

        # import all class names to globals
        for (k, v) in model_accessor.all_model_classes.items():
            globals()[k] = v

        from multistructlog import create_logger
        log = create_logger()

        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)
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#!/usr/bin/env python

# This imports and runs ../../xos-observer.py

import importlib
import os
import sys

from xosconfig import Config
config_file = os.path.abspath(
    os.path.dirname(os.path.realpath(__file__)) + '/sepcservice_config.yaml')

Config.init(config_file, 'synchronizer-config-schema.yaml')

synchronizer_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                 "../../synchronizers/new_base")
sys.path.append(synchronizer_path)
mod = importlib.import_module("xos-synchronizer")
mod.main()
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Runs the standard XOS synchronizer

import os
from xossynchronizer import Synchronizer
from xosconfig import Config

base_config_file = os.path.abspath(
    os.path.dirname(os.path.realpath(__file__)) + '/config.yaml')
mounted_config_file = os.path.abspath(
    os.path.dirname(os.path.realpath(__file__)) + '/mounted_config.yaml')

if os.path.isfile(mounted_config_file):
    Config.init(base_config_file, 'synchronizer-config-schema.yaml',
                mounted_config_file)
else:
    Config.init(base_config_file, 'synchronizer-config-schema.yaml')

Synchronizer().run()
Beispiel #50
0
    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, [("olt-service", "volt.xproto"),
                                              ("rcord", "rcord.xproto")])

        import xossynchronizer.modelaccessor
        reload(xossynchronizer.modelaccessor
               )  # in case nose2 loaded it in a previous test

        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

        from sync_olt_device import SyncOLTDevice, DeferredException
        self.sync_step = SyncOLTDevice

        pon_port = Mock()
        pon_port.port_id = "00ff00"

        # create a mock ONOS Service
        onos = Mock()
        onos.name = "ONOS"
        onos.leaf_model.rest_hostname = "onos"
        onos.leaf_model.rest_port = 4321
        onos.leaf_model.rest_username = "******"
        onos.leaf_model.rest_password = "******"

        # Create a mock OLTDevice
        o = Mock()
        o.volt_service.voltha_url = "voltha_url"
        o.volt_service.voltha_port = 1234
        o.volt_service.voltha_user = "******"
        o.volt_service.voltha_pass = "******"

        o.volt_service.provider_services = [onos]

        o.device_type = "ponsim_olt"
        o.host = "172.17.0.1"
        o.port = "50060"
        o.uplink = "129"
        o.driver = "voltha"
        o.name = "Test Device"
        o.admin_state = "ENABLED"

        # feedback state
        o.device_id = None
        o.oper_status = None
        o.serial_number = None
        o.of_id = None
        o.id = 1

        o.tologdict.return_value = {'name': "Mock VOLTServiceInstance"}

        o.save_changed_fields.return_value = "Saved"

        o.pon_ports.all.return_value = [pon_port]

        self.o = o

        self.voltha_devices_response = {"id": "123", "serial_number": "foobar"}

        self.tp = TechnologyProfile(technology="xgspon",
                                    profile_id=64,
                                    profile_value="{}")
    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 sync_onos_app import SyncONOSApp, DeferredException, 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 = SyncONOSApp

        onos = ONOSService()
        onos.rest_hostname = "onos-url"
        onos.rest_port = "8181"
        onos.rest_username = "******"
        onos.rest_password = "******"

        self.onos_app = Mock(spec=[
            'id', 'name', 'app_id', 'dependencies', 'owner', 'url',
            'backend_code', 'version', 'tologdict'
        ])
        self.onos_app.id = 1
        self.onos_app.name = "vrouter"
        self.onos_app.app_id = "org.onosproject.vrouter"
        self.onos_app.dependencies = ""
        self.onos_app.owner.leaf_model = onos
        self.onos_app.url = None
        self.onos_app.class_names = "ONOSApp"
        self.onos_app.tologdict.return_value = ""

        self.si = Mock()
        self.si.id = 1
        self.si.leaf_model = self.onos_app

        self.vrouter_app_response = {
            "name": "org.onosproject.vrouter",
            "version": "1.13.1",
        }

        self.onos_app_attribute = Mock(
            spec=['id', 'service_instance', 'name', 'value'])
        self.onos_app_attribute.id = 1
        self.onos_app_attribute.service_instance = self.si
        self.onos_app_attribute.name = "/onos/v1/network/configuration/apps/org.opencord.olt"
        self.onos_app_attribute.value = {
            "kafka": {
                "bootstrapServers":
                "cord-kafka-kafka.default.svc.cluster.local:9092"
            }
        }
    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")

        # 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, [("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 mock_modelaccessor import MockObjectList
        from xossynchronizer.modelaccessor import model_accessor
        self.model_accessor = model_accessor

        # necessary to reset XOSKafkaProducer's call_count
        import onos_event
        reload(onos_event)

        from onos_event import OnosPortEventStep, XOSKafkaProducer
        from onos_event import 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.volt_service = VOLTService(name="volt",
                                        id=1112,
                                        backend_code=1,
                                        backend_status="succeeded")

        self.oltdevice = OLTDevice(name="myolt",
                                   device_id="of:0000000000000001",
                                   switch_datapath_id="of:0000000000000001",
                                   switch_port="1")

        self.ponport = PONPort(olt_device = self.oltdevice)

        self.onudevice = ONUDevice(pon_port = self.ponport)

        self.subscriber = RCORDSubscriber(name="somesubscriber")
        self.voltsi = VOLTServiceInstance()

        # chain it all together
        self.oltdevice.pon_ports = MockObjectList([self.ponport])
        self.ponport.onu_devices = MockObjectList([self.onudevice])
        self.onudevice.volt_service_instances = MockObjectList([self.voltsi])
        self.voltsi.westbound_service_instances = [self.subscriber]

        self.log = Mock()
    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)
Beispiel #54
0
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from django import VERSION as DJANGO_VERSION
import os
import warnings

# Initializing xosconfig module
from xosconfig import Config
from xosconfig.config import INITIALIZED as CONFIG_INITIALIZED

# this really shouldn't be called from settings.py.
if not CONFIG_INITIALIZED:
    Config.init()

GEOIP_PATH = "/usr/share/GeoIP"
XOS_DIR = Config.get("xos_dir")

DEBUG = True
TEMPLATE_DEBUG = DEBUG

# Enable CORS requests, needed to enable layered XOS
CORS_ORIGIN_ALLOW_ALL = True

ADMINS = (
    # ('Your Name', '*****@*****.**'),
)

# LOGIN_REDIRECT_URL = '/admin/core/user'
    def setUp(self):
        global DeferredException

        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"),
                                              ("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
        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.model_accessor = model_accessor
        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.fcservice = VOLTService(name="myoltservice",
                                     id=1112,
                                     backend_code=1,
                                     backend_status="succeeded",
                                     provider_services=[self.onos])

        self.fcsi1 = VOLTServiceInstance(name="myfcsi1",
                                         owner=self.fcservice,
                                         backend_code=1,
                                         backend_status="succeeded")

        self.fcsi2 = VOLTServiceInstance(name="myfcsi2",
                                         owner=self.fcservice,
                                         backend_code=1,
                                         backend_status="succeeded")

        self.fcservice.service_instances = MockObjectList(
            [self.fcsi1, self.fcsi2])

        self.log = Mock()
Beispiel #56
0
    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, [("olt-service", "volt.xproto"),
                                                ("vsg", "vsg.xproto"),
                                                ("rcord", "rcord.xproto"),])

        import xossynchronizer.modelaccessor
        reload(xossynchronizer.modelaccessor)      # in case nose2 loaded it in a previous test

        from xossynchronizer.modelaccessor import model_accessor
        self.model_accessor = model_accessor

        from pull_olts import OLTDevicePullStep

        # import all class names to globals
        for (k, v) in model_accessor.all_model_classes.items():
            globals()[k] = v

        self.sync_step = OLTDevicePullStep

        # mock volt service
        self.volt_service = Mock()
        self.volt_service.id = "volt_service_id"
        self.volt_service.voltha_url = "voltha_url"
        self.volt_service.voltha_user = "******"
        self.volt_service.voltha_pass = "******"
        self.volt_service.voltha_port = 1234

        # mock voltha responses
        self.devices = {
            "items": [
                {
                    "id": "test_id",
                    "type": "simulated_olt",
                    "host_and_port": "172.17.0.1:50060",
                    "admin_state": "ENABLED",
                    "oper_status": "ACTIVE",
                    "serial_number": "serial_number",
                }
            ]
        }

        self.logical_devices = {
            "items": [
                {
                    "root_device_id": "test_id",
                    "id": "of_id",
                    "datapath_id": "55334486016"
                }
            ]
        }

        self.ports = {
            "items": [
                {
                    "label": "PON port",
                    "port_no": 1,
                    "type": "PON_OLT",
                    "admin_state": "ENABLED",
                    "oper_status": "ACTIVE"
                },
                {
                    "label": "NNI facing Ethernet port",
                    "port_no": 2,
                    "type": "ETHERNET_NNI",
                    "admin_state": "ENABLED",
                    "oper_status": "ACTIVE"
                }
            ]
        }
Beispiel #57
0
    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
        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",
                                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()
Beispiel #58
0
# Copyright 2017-present Open Networking Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
from xosconfig import Config

current_dir = os.path.dirname(os.path.realpath(__file__))
config_file = os.path.join(current_dir, "test_config.yaml")
config_schema = os.path.join(current_dir, "../src/xos-tosca-config-schema.yaml")
Config.clear()
Config.init(config_file, config_schema)
    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()
Beispiel #60
0
    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 multistructlog import create_logger
        self.log = create_logger(Config().get('logging'))

        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 helpers import NttHelpers

        # import all class names to globals
        for (k, v) in model_accessor.all_model_classes.items():
            globals()[k] = v

        self.helpers = NttHelpers
        self.model_accessor = model_accessor

        self._volt = VOLTService()
        self._volt.id = 1

        self.volt = Service()
        self.volt.id = 1
        self.volt.name = "vOLT"
        self.volt.leaf_model = self._volt

        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.technologyProfile = TechnologyProfile()
        self.technologyProfile.profile_id = 64
        self.technologyProfile.profile_value = '{"profile_type": "EPON","epon_attribute": {"package_type": "A"}}'

        self.ntt_si = NttWorkflowDriverServiceInstance(
            serial_number="BRCM1234",
            owner=self.volt,
            owner_id=self.volt.id,
            mac_address="0a0a0a",
            of_dpid="of:1234")

        self.whitelist_entry = NttWorkflowDriverWhiteListEntry(
            mac_address="0a0a0a",
            owner=self.volt,
            owner_id=self.volt.id,
            pon_port_from=1234,
            pon_port_to=1235,
        )