本文整理汇总了Python中atomicapp.nulecule.base.Nulecule类的典型用法代码示例。如果您正苦于以下问题:Python Nulecule类的具体用法?Python Nulecule怎么用?Python Nulecule使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Nulecule类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_load_components
def test_load_components(self, MockNuleculeComponent):
graph = [
{
'name': 'app1',
'source': 'docker://somecontainer',
'params': []
},
{
'name': 'app2',
'artifacts': [
{'a': 'b'}
]
}
]
config = Config(answers={})
n = Nulecule('some-id', '0.0.2', graph, 'some/path', config=config)
n.load_components()
MockNuleculeComponent.assert_any_call(
graph[0]['name'], n.basepath, 'somecontainer',
graph[0]['params'], None, config)
MockNuleculeComponent.assert_any_call(
graph[1]['name'], n.basepath, None,
graph[1].get('params'), graph[1].get('artifacts'), config)
示例2: unpack
def unpack(self, update=False, dryrun=False, nodeps=False, config=None):
"""
Unpacks a Nulecule application from a Nulecule image to a path
or load a Nulecule that already exists locally.
Args:
update (bool): Update existing Nulecule application in
app_path, if True
dryrun (bool): Do not make any change to the host system
nodeps (bool): Do not unpack external dependencies
config (dict): Config data, if any, to use for unpacking
Returns:
A Nulecule instance.
"""
logger.debug("Request to unpack to %s to %s" % (self.image, self.app_path))
# If the user provided an image then unpack it and return the
# resulting Nulecule. Else, load from existing path
if self.image:
return Nulecule.unpack(
self.image, self.app_path, config=config, nodeps=nodeps, dryrun=dryrun, update=update
)
else:
return Nulecule.load_from_path(self.app_path, dryrun=dryrun, config=config)
示例3: test_load_config_without_default_provider
def test_load_config_without_default_provider(self):
"""
Test Nulecule load_config without specifying a default provider.
"""
config = Config()
params = [
{
"name": "key1",
"default": "val1",
},
{
"name": "key3",
"default": "val3"
}
]
graph = [
{
"name": "component1",
"params": [
{
"name": "key1",
},
{
"name": "key2",
"default": "val2"
}
],
"artifacts": []
}
]
n = Nulecule(id='some-id', specversion='0.0.2', metadata={},
graph=graph, params=params, basepath='some/path',
config=config)
n.load_components()
n.load_config()
self.assertEqual(n.config.runtime_answers(), {
'general': {
'namespace': 'default',
'provider': 'kubernetes',
'key1': 'val1',
'key3': 'val3'
},
'component1': {
'key2': 'val2'
}
})
self.assertEqual(
n.components[0].config.context(n.components[0].namespace),
{'key3': 'val3',
'key2': 'val2',
'key1': 'val1',
'namespace': 'default',
'provider': 'kubernetes'}
)
示例4: test_run
def test_run(self):
provider = 'docker'
dryrun = False
mock_component_1 = mock.Mock()
mock_component_2 = mock.Mock()
n = Nulecule('some-id', '0.0.2', {}, [], 'some/path')
n.components = [mock_component_1, mock_component_2]
n.run(provider)
mock_component_1.run.assert_called_once_with(provider, dryrun)
mock_component_2.run.assert_called_once_with(provider, dryrun)
示例5: test_stop
def test_stop(self):
provider = "docker"
dryrun = False
mock_component_1 = mock.Mock()
mock_component_2 = mock.Mock()
n = Nulecule("some-id", "0.0.2", {}, [], "some/path")
n.components = [mock_component_1, mock_component_2]
n.stop(provider)
mock_component_1.stop.assert_called_once_with(provider, dryrun)
mock_component_2.stop.assert_called_once_with(provider, dryrun)
示例6: test_render
def test_render(self):
mock_component_1 = mock.Mock()
mock_component_2 = mock.Mock()
provider_key = "foo"
dryrun = True
n = Nulecule("some-id", "0.0.2", {}, [], "some/path")
n.components = [mock_component_1, mock_component_2]
n.render(provider_key, dryrun)
mock_component_1.render.assert_called_once_with(provider_key=provider_key, dryrun=dryrun)
mock_component_2.render.assert_called_once_with(provider_key=provider_key, dryrun=dryrun)
示例7: test_stop
def test_stop(self):
provider = 'docker'
dryrun = False
mock_component_1 = mock.Mock()
mock_component_2 = mock.Mock()
config = Config(answers={})
n = Nulecule('some-id', '0.0.2', {}, [], 'some/path', config=config)
n.components = [mock_component_1, mock_component_2]
n.stop(provider)
mock_component_1.stop.assert_called_once_with(provider, dryrun)
mock_component_2.stop.assert_called_once_with(provider, dryrun)
示例8: test_render
def test_render(self):
mock_component_1 = mock.Mock()
mock_component_2 = mock.Mock()
provider_key = 'foo'
dryrun = True
n = Nulecule('some-id', '0.0.2', {}, [], 'some/path')
n.components = [mock_component_1, mock_component_2]
n.render(provider_key, dryrun)
mock_component_1.render.assert_called_once_with(
provider_key=provider_key, dryrun=dryrun)
mock_component_2.render.assert_called_once_with(
provider_key=provider_key, dryrun=dryrun)
示例9: test_load_config_without_specified_provider
def test_load_config_without_specified_provider(self):
"""
Test Nulecule load_config without specifying a provider.
"""
config = {"general": {}, "group1": {"a": "b"}}
mock_component_1 = mock.Mock()
mock_component_1.config = {"group1": {"a": "c", "k": "v"}, "group2": {"1": "2"}}
n = Nulecule(id="some-id", specversion="0.0.2", metadata={}, graph=[], basepath="some/path")
n.components = [mock_component_1]
n.load_config(config)
self.assertEqual(
n.config, {"general": {"provider": "kubernetes"}, "group1": {"a": "b", "k": "v"}, "group2": {"1": "2"}}
)
示例10: test_load_components
def test_load_components(self, MockNuleculeComponent):
graph = [
{"name": "app1", "source": "docker://somecontainer", "params": []},
{"name": "app2", "artifacts": [{"a": "b"}]},
]
n = Nulecule("some-id", "0.0.2", graph, "some/path", {})
n.load_components()
MockNuleculeComponent.assert_any_call(
graph[0]["name"], n.basepath, "somecontainer", graph[0]["params"], None, {}
)
MockNuleculeComponent.assert_any_call(
graph[1]["name"], n.basepath, None, graph[1].get("params"), graph[1].get("artifacts"), {}
)
示例11: test_load_config
def test_load_config(self):
config = {'group1': {'a': 'b'}}
mock_component_1 = mock.Mock()
mock_component_1.config = {
'group1': {'a': 'c', 'k': 'v'},
'group2': {'1': '2'}
}
n = Nulecule('some-id', '0.0.2', {}, [], 'some/path')
n.components = [mock_component_1]
n.load_config(config)
self.assertEqual(n.config, {
'group1': {'a': 'b', 'k': 'v'},
'group2': {'1': '2'}
})
示例12: test_load_config_without_specified_provider
def test_load_config_without_specified_provider(self):
"""
Test Nulecule load_config without specifying a provider.
"""
config = {'general': {}, 'group1': {'a': 'b'}}
mock_component_1 = mock.Mock()
mock_component_1.config = {
'group1': {'a': 'c', 'k': 'v'},
'group2': {'1': '2'}
}
n = Nulecule(id='some-id', specversion='0.0.2', metadata={}, graph=[], basepath='some/path')
n.components = [mock_component_1]
n.load_config(config)
self.assertEqual(n.config, {
'general': {'provider': 'kubernetes'},
'group1': {'a': 'b', 'k': 'v'},
'group2': {'1': '2'}
})
示例13: test_load_config_with_defaultprovider
def test_load_config_with_defaultprovider(self):
"""
Test Nulecule load_config with default provider specified
in global params in Nulecule spec.
"""
config = {'general': {}, 'group1': {'a': 'b'}}
mock_component_1 = mock.Mock()
mock_component_1.config = {
'group1': {'a': 'c', 'k': 'v'},
'group2': {'1': '2'}
}
n = Nulecule(id='some-id', specversion='0.0.2', metadata={}, graph=[],
basepath='some/path',
params=[{'name': 'provider', 'default': 'some-provider'}])
n.components = [mock_component_1]
n.load_config(config)
self.assertEqual(n.config, {
'general': {'provider': 'some-provider'},
'group1': {'a': 'b', 'k': 'v'},
'group2': {'1': '2'}
})
示例14: test_load_config_with_defaultprovider_overridden_by_provider_in_answers
def test_load_config_with_defaultprovider_overridden_by_provider_in_answers(self):
"""
Test Nulecule load_config with default provider specified
in global params in Nulecule spec, but overridden in answers config.
"""
config = {"general": {"provider": "new-provider"}, "group1": {"a": "b"}}
mock_component_1 = mock.Mock()
mock_component_1.config = {"group1": {"a": "c", "k": "v"}, "group2": {"1": "2"}}
n = Nulecule(
id="some-id",
specversion="0.0.2",
metadata={},
graph=[],
basepath="some/path",
params=[{"name": "provider", "default": "some-provider"}],
)
n.components = [mock_component_1]
n.load_config(config)
self.assertEqual(
n.config, {"general": {"provider": "new-provider"}, "group1": {"a": "b", "k": "v"}, "group2": {"1": "2"}}
)
示例15: stop
def stop(self, cli_provider, **kwargs):
"""
Stops a running Nulecule application.
Args:
cli_provider (str): Provider running the Nulecule application
kwargs (dict): Extra keyword arguments
"""
# For stop we use the generated answer file from the run
self.answers = Utils.loadAnswers(os.path.join(self.app_path, ANSWERS_RUNTIME_FILE))
dryrun = kwargs.get("dryrun") or False
self.nulecule = Nulecule.load_from_path(self.app_path, config=self.answers, dryrun=dryrun)
self.nulecule.load_config(config=self.answers)
self.nulecule.render(cli_provider, dryrun=dryrun)
self.nulecule.stop(cli_provider, dryrun)