• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python xosconfig.Config类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中xosconfig.Config的典型用法代码示例。如果您正苦于以下问题:Python Config类的具体用法?Python Config怎么用?Python Config使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Config类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: run_playbook

def run_playbook(ansible_hosts, ansible_config, fqp, opts):
    args = {"ansible_hosts": ansible_hosts,
            "ansible_config": ansible_config,
            "fqp": fqp,
            "opts": opts,
            "config_file": Config.get_config_file()}

    keep_temp_files = Config.get("keep_temp_files")

    dir = tempfile.mkdtemp()
    args_fn = None
    result_fn = None
    try:
        log.info("creating args file",dir = dir)

        args_fn = os.path.join(dir, "args")
        result_fn = os.path.join(dir, "result")

        open(args_fn, "w").write(pickle.dumps(args))

        ansible_main_fn = os.path.join(os.path.dirname(__file__), "ansible_main.py")

        os.system("python %s %s %s" % (ansible_main_fn, args_fn, result_fn))

        result = pickle.loads(open(result_fn).read())

        if hasattr(result, "exception"):
            log.error("Exception in playbook",exception = result["exception"])

        stats = result.get("stats", None)
        aresults = result.get("aresults", None)
    except Exception,e:
        log.exception("Exception running ansible_main")
        stats = None
        aresults = None
开发者ID:vpramo,项目名称:xos-1,代码行数:35,代码来源:ansible_helper.py


示例2: setUp

    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)
开发者ID:opencord,项目名称:xos,代码行数:32,代码来源:test_load.py


示例3: setUp

    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()
开发者ID:opencord,项目名称:xos,代码行数:26,代码来源:test_diffs.py


示例4: setUp

    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()
开发者ID:opencord,项目名称:fabric,代码行数:34,代码来源:test_model_policy_compute_node.py


示例5: init

    def init():

        global log
        global kafka_producer

        if not log:
            log = create_logger(Config().get("logging"))

        if kafka_producer:
            raise Exception("XOSKafkaProducer already initialized")

        else:
            log.info(
                "Connecting to Kafka with bootstrap servers: %s"
                % Config.get("kafka_bootstrap_servers")
            )

            try:
                producer_config = {
                    "bootstrap.servers": ",".join(Config.get("kafka_bootstrap_servers"))
                }

                kafka_producer = confluent_kafka.Producer(**producer_config)

                log.info("Connected to Kafka: %s" % kafka_producer)

            except confluent_kafka.KafkaError as e:
                log.exception("Kafka Error: %s" % e)
开发者ID:opencord,项目名称:xos,代码行数:28,代码来源:xoskafkaproducer.py


示例6: test_get_child_level

 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")
开发者ID:opencord,项目名称:xos,代码行数:7,代码来源:test_config.py


示例7: test_invalid_format

 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: ''.")
开发者ID:vpramo,项目名称:xos-1,代码行数:7,代码来源:config_test.py


示例8: test_get_config_file

 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)
开发者ID:opencord,项目名称:xos,代码行数:7,代码来源:test_config.py


示例9: test_missing_file_exception

 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")
开发者ID:vpramo,项目名称:xos-1,代码行数:7,代码来源:config_test.py


示例10: test_yaml_not_valid

 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")
开发者ID:vpramo,项目名称:xos-1,代码行数:7,代码来源:config_test.py


示例11: test_config_not_initialized

 def test_config_not_initialized(self):
     """
     [XOS-Config] Raise if accessing properties without initialization
     """
     with self.assertRaises(Exception) as e:
         Config.get("database")
     self.assertEqual(e.exception.message, "[XOS-Config] Module has not been initialized")
开发者ID:vpramo,项目名称:xos-1,代码行数:7,代码来源:config_test.py


示例12: config_accessor_grpcapi

def config_accessor_grpcapi():
    global orig_sigint

    grpcapi_endpoint = Config.get("accessor.endpoint")
    grpcapi_username = Config.get("accessor.username")
    grpcapi_password = Config.get("accessor.password")

    # if password starts with "@", then retreive the password from a file
    if grpcapi_password.startswith("@"):
        fn = grpcapi_password[1:]
        if not os.path.exists(fn):
            raise Exception("%s does not exist" % fn)
        grpcapi_password = open(fn).readline().strip()

    from xosapi.xos_grpc_client import SecureClient
    from twisted.internet import reactor

    grpcapi_client = SecureClient(endpoint=grpcapi_endpoint, username=grpcapi_username, password=grpcapi_password)
    grpcapi_client.set_reconnect_callback(functools.partial(grpcapi_reconnect, grpcapi_client, reactor))
    grpcapi_client.start()

    # Start reactor. This will cause the client to connect and then execute
    # grpcapi_callback().

    # Reactor will take over SIGINT during reactor.run(), but does not return it when reactor.stop() is called.

    orig_sigint = signal.getsignal(signal.SIGINT)

    # Start reactor. This will cause the client to connect and then execute
    # grpcapi_callback().

    reactor.run()
开发者ID:vpramo,项目名称:xos-1,代码行数:32,代码来源:modelaccessor.py


示例13: test_get_missing_param

 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)
开发者ID:opencord,项目名称:xos,代码行数:7,代码来源:test_config.py


示例14: _test_get_child_level

 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")
开发者ID:vpramo,项目名称:xos-1,代码行数:7,代码来源:config_test.py


示例15: test_get_default_val_for_missing_param

 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")
开发者ID:opencord,项目名称:xos,代码行数:7,代码来源:test_config.py


示例16: test_initialize_only_once

 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")
开发者ID:opencord,项目名称:xos,代码行数:8,代码来源:test_config.py


示例17: test_env_override

 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"]
开发者ID:vpramo,项目名称:xos-1,代码行数:9,代码来源:config_test.py


示例18: test_yaml_not_valid

 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:")
     )
开发者ID:opencord,项目名称:xos,代码行数:9,代码来源:test_config.py


示例19: test_fail_get_service_info

 def test_fail_get_service_info(self):
     """
     [XOS-Config] Should query registrator and return an exception if it"s down
     """
     with patch("xosconfig.config.requests.get") as mock_get:
         mock_get.return_value.ok = False
         with self.assertRaises(Exception) as e:
             Config.get_service_info("missing-service")
         self.assertEqual(e.exception.message, "[XOS-Config] Registrator is down")
开发者ID:vpramo,项目名称:xos-1,代码行数:9,代码来源:config_test.py


示例20: test_config_override

 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")
开发者ID:opencord,项目名称:xos,代码行数:9,代码来源:test_config.py



注:本文中的xosconfig.Config类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python generator.XOSGenerator类代码示例发布时间:2022-05-26
下一篇:
Python models.DBSession类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap