本文整理汇总了Python中calico.felix.config.Config类的典型用法代码示例。如果您正苦于以下问题:Python Config类的具体用法?Python Config怎么用?Python Config使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Config类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_default_config
def test_default_config(self):
"""
Test various ways of defaulting config.
"""
files = [ "felix_missing.cfg", # does not exist
"felix_empty.cfg", # empty file
"felix_empty_section.cfg", # file with empty section
"felix_extra.cfg", # extra config is just logged
]
for filename in files:
config = Config("calico/felix/test/data/%s" % filename)
host_dict = { "InterfacePrefix": "blah",
"MetadataPort": 123 }
global_dict = { "InterfacePrefix": "overridden",
"MetadataAddr": "1.2.3.4" }
with mock.patch('calico.common.complete_logging'):
config.report_etcd_config(host_dict, global_dict)
# Test defaulting.
self.assertEqual(config.ETCD_ADDR, "localhost:4001")
self.assertEqual(config.HOSTNAME, socket.gethostname())
self.assertEqual(config.IFACE_PREFIX, "blah")
self.assertEqual(config.METADATA_PORT, 123)
self.assertEqual(config.METADATA_IP, "1.2.3.4")
示例2: test_env_var_override
def test_env_var_override(self):
"""
Test environment variables override config options,
"""
with mock.patch.dict("os.environ", {"FELIX_ETCDADDR": "9.9.9.9:1234",
"FELIX_METADATAPORT": "999"}):
config = Config("calico/felix/test/data/felix_section.cfg")
host_dict = { "InterfacePrefix": "blah",
"StartupCleanupDelay": "42",
"MetadataAddr": "4.3.2.1",
"MetadataPort": "123" }
global_dict = { "InterfacePrefix": "blah",
"StartupCleanupDelay": "99",
"MetadataAddr": "5.4.3.2",
"MetadataPort": "123" }
with mock.patch('calico.common.complete_logging'):
config.report_etcd_config(host_dict, global_dict)
self.assertEqual(config.ETCD_ADDR, "9.9.9.9:1234")
self.assertEqual(config.HOSTNAME, socket.gethostname())
self.assertEqual(config.LOGFILE, "/log/nowhere.log")
self.assertEqual(config.IFACE_PREFIX, "whatever")
self.assertEqual(config.METADATA_PORT, 999)
self.assertEqual(config.METADATA_IP, "1.2.3.4")
self.assertEqual(config.STARTUP_CLEANUP_DELAY, 42)
示例3: test_default_config
def test_default_config(self):
"""
Test various ways of defaulting config.
"""
files = [ "felix_missing.cfg", # does not exist
"felix_empty.cfg", # empty file
"felix_empty_section.cfg", # file with empty section
"felix_extra.cfg", # extra config is just logged
]
for filename in files:
host = socket.gethostname()
host_path = "/calico/host/%s/config/" % host
config = Config("calico/felix/test/data/%s" % filename)
cfg_dict = { "InterfacePrefix": "blah",
"ExtraJunk": "whatever", #ignored
"ResyncIntervalSecs": "123" }
config.update_config(cfg_dict)
# Test defaulting.
self.assertEqual(config.ETCD_ADDR, "localhost:4001")
self.assertEqual(config.HOSTNAME, host)
self.assertEqual(config.IFACE_PREFIX, "blah")
self.assertEqual(config.RESYNC_INT_SEC, 123)
示例4: test_ip_in_ip_enabled
def test_ip_in_ip_enabled(self):
test_values = [
("true", True),
("t", True),
("True", True),
("1", True),
(1, True),
("yes", True),
("y", True),
("false", False),
("f", False),
("False", False),
("0", False),
(0, False),
("no", False),
("n", False),
]
for value, expected in test_values:
with mock.patch('calico.common.complete_logging'):
config = Config("calico/felix/test/data/felix_missing.cfg")
cfg_dict = { "InterfacePrefix": "blah",
"IpInIpEnabled": value }
config.report_etcd_config({}, cfg_dict)
self.assertEqual(config.IP_IN_IP_ENABLED, expected,
"%r was mis-interpreted as %r" %
(value, config.IP_IN_IP_ENABLED))
示例5: test_no_iface_prefix
def test_no_iface_prefix(self):
with mock.patch('calico.common.complete_logging'):
config = Config("calico/felix/test/data/felix_missing.cfg")
cfg_dict = {}
with self.assertRaisesRegexp(ConfigException,
"Missing undefaulted value.*InterfacePrefix"):
config.report_etcd_config({}, cfg_dict)
示例6: test_metadata_port_not_int
def test_metadata_port_not_int(self):
config = Config("calico/felix/test/data/felix_missing.cfg")
cfg_dict = { "InterfacePrefix": "blah",
"MetadataAddr": "127.0.0.1",
"MetadataPort": "bloop" }
with self.assertRaisesRegexp(ConfigException,
"Field was not integer.*MetadataPort"):
config.report_etcd_config({}, cfg_dict)
示例7: test_blank_metadata_addr
def test_blank_metadata_addr(self):
config = Config("calico/felix/test/data/felix_missing.cfg")
cfg_dict = { "InterfacePrefix": "blah",
"MetadataAddr": "",
"MetadataPort": "123" }
with self.assertRaisesRegexp(ConfigException,
"Blank value.*MetadataAddr"):
config.report_etcd_config({}, cfg_dict)
示例8: test_bad_metadata_addr
def test_bad_metadata_addr(self):
config = Config("calico/felix/test/data/felix_missing.cfg")
cfg_dict = { "InterfacePrefix": "blah",
"MetadataAddr": "bloop",
"MetadataPort": "123" }
with self.assertRaisesRegexp(ConfigException,
"Invalid or unresolvable.*MetadataAddr"):
config.report_etcd_config({}, cfg_dict)
self.m_gethostbyname.assert_has_calls([mock.call("bloop")])
示例9: test_bad_log_level
def test_bad_log_level(self):
for field in ("LogSeverityFile", "LogSeverityScreen", "LogSeveritySys"):
config = Config("calico/felix/test/data/felix_missing.cfg")
cfg_dict = { "LogInterfacePrefix": "blah",
field: "bloop" }
with self.assertRaisesRegexp(ConfigException,
"Invalid log level.*%s" % field):
config.report_etcd_config({}, cfg_dict)
示例10: test_no_logfile
def test_no_logfile(self):
# Logging to file can be excluded by explicitly saying "none"
config = Config("calico/felix/test/data/felix_missing.cfg")
cfg_dict = { "InterfacePrefix": "blah",
"LogFilePath": "None" }
with mock.patch('calico.common.complete_logging'):
config.report_etcd_config({}, cfg_dict)
self.assertEqual(config.LOGFILE, None)
示例11: test_ip_in_ip_enabled_bad
def test_ip_in_ip_enabled_bad(self):
with mock.patch('calico.common.complete_logging'):
config = Config("calico/felix/test/data/felix_missing.cfg")
cfg_dict = { "InterfacePrefix": "blah",
"IpInIpEnabled": "blah" }
with self.assertRaisesRegexp(ConfigException,
"Field was not a valid Boolean"
".*IpInIpEnabled"):
config.report_etcd_config({}, cfg_dict)
示例12: test_metadata_port_not_valid_1
def test_metadata_port_not_valid_1(self):
for i in (0, -1, 99999):
log.debug("Test invalid metadata port %d", i)
config = Config("calico/felix/test/data/felix_missing.cfg")
cfg_dict = { "InterfacePrefix": "blah",
"MetadataAddr": "127.0.0.1",
"MetadataPort": i }
with self.assertRaisesRegexp(ConfigException,
"Invalid field value.*MetadataPort"):
config.report_etcd_config({}, cfg_dict)
示例13: test_default_ipset_size
def test_default_ipset_size(self):
"""
Test that ipset size is defaulted if out of range.
"""
with mock.patch("calico.common.complete_logging"):
config = Config("calico/felix/test/data/felix_missing.cfg")
cfg_dict = {"InterfacePrefix": "blah", "MaxIpsetSize": "0"}
with mock.patch("calico.common.complete_logging"):
config.report_etcd_config({}, cfg_dict)
self.assertEqual(config.MAX_IPSET_SIZE, 2 ** 20)
示例14: test_reporting_interval_not_int
def test_reporting_interval_not_int(self):
"""
Test exception is raised if status reporting interval is invalid.
"""
with mock.patch('calico.common.complete_logging'):
config = Config("calico/felix/test/data/felix_missing.cfg")
cfg_dict = { "InterfacePrefix": "blah",
"ReportingIntervalSecs": "NaN"}
with self.assertRaisesRegexp(ConfigException,
"Field was not integer.*"):
config.report_etcd_config({}, cfg_dict)
示例15: test_no_metadata
def test_no_metadata(self):
# Metadata can be excluded by explicitly saying "none"
config = Config("calico/felix/test/data/felix_missing.cfg")
cfg_dict = { "InterfacePrefix": "blah",
"MetadataAddr": "NoNe",
"MetadataPort": 123 }
with mock.patch('calico.common.complete_logging'):
config.report_etcd_config({}, cfg_dict)
# Test defaulting.
self.assertEqual(config.METADATA_IP, None)
self.assertEqual(config.METADATA_PORT, None)