def env_prod(): environment = Environment( "production", basedir=os.path.dirname(__file__) + "/fixture/basic_service", ) environment.load() return environment
def test_resolver_overrides_invalid_address(sample_service): e = Environment('test-resolver-invalid') e.load() with pytest.raises(batou.InvalidIPAddressError) as err: e.configure() assert "thisisinvalid" == err.value.address
class Deployment(object): environment = None def __init__(self, env_name, host_name, overrides, host_data, timeout, platform): self.env_name = env_name self.host_name = host_name self.overrides = overrides self.host_data = host_data self.timeout = timeout self.platform = platform def load(self): from batou.environment import Environment self.environment = Environment(self.env_name, self.timeout, self.platform) self.environment.deployment = self self.environment.load() self.environment.overrides = self.overrides for hostname, data in self.host_data.items(): self.environment.hosts[hostname].data.update(data) self.environment.configure() def deploy(self, root, predict_only): root = self.environment.get_root(root, self.host_name) root.component.deploy(predict_only)
def test_service_early_resource(): env = Environment("dev", basedir=os.path.dirname(__file__) + "/fixture/service_early_resource") env.load() env.configure() assert env.resources.get("zeo") == ["127.0.0.1:9000"]
def test_service_early_resource(): env = Environment('dev', basedir=os.path.dirname(__file__) + '/fixture/service_early_resource') env.load() env.configure() assert env.resources.get('zeo') == ['127.0.0.1:9000']
def test_log_in_component_configure_is_put_out(output, sample_service): e = Environment("test-with-provide-require") e.load() e.configure() log = "\n".join(c[0][0].strip() for c in output.call_args_list) # Provide is *always* logged first, due to provide/require ordering. assert ( """\ Provide Pre sub Sub! Post sub""" == log ) output.reset_mock() for root in e.root_dependencies(): root.component.deploy(True) log = "\n".join(c[0][0].strip() for c in output.call_args_list) assert ( """\ localhost > Hello localhost: <Hello (localhost) "Hello"> verify: asdf=None\ """ == log )
def test_resolver_overrides(sample_service): e = Environment('test-resolver') e.load() assert {'localhost': '127.0.0.2'} == e._resolve_override assert {'localhost': '::2'} == e._resolve_v6_override assert '127.0.0.2' == batou.utils.resolve('localhost') assert '::2' == batou.utils.resolve_v6('localhost', 0)
def test_remote_deployment_initializable(sample_service): cmd('hg init') with open('.hg/hgrc', 'w') as f: f.write('[paths]\ndefault=https://example.com') env = Environment('test-with-env-config') env.load() env.configure() Deployment(env, platform='', jobs=1, timeout=30, dirty=False)
def test_remote_deployment_initializable(sample_service): cmd("hg init") with open(".hg/hgrc", "w") as f: f.write("[paths]\ndefault=https://example.com") env = Environment("test-with-env-config") env.load() env.configure() Deployment(env, platform="", jobs=1, timeout=30, dirty=False)
def test_resolver_overrides(sample_service): e = Environment("test-resolver") e.load() assert {"localhost": "127.0.0.2"} == e._resolve_override assert {"localhost": "::2"} == e._resolve_v6_override assert "127.0.0.2" == batou.utils.resolve("localhost") assert "::2" == batou.utils.resolve_v6("localhost", 0)
def test_load_should_use_config(sample_service): e = Environment("test-with-env-config") e.load() assert e.service_user == "joe" assert e.host_domain == "example.com" assert e.branch == "release" assert e.hosts["foo1"].service_user == "bob"
def test_load_ignores_predefined_environment_settings(sample_service): e = Environment('test-with-env-config') e.service_user = '******' e.host_domain = 'sample.com' e.branch = 'default' e.load() assert e.service_user == 'bob' assert e.host_domain == 'sample.com' assert e.branch == 'default'
def test_multiple_components(sample_service): e = Environment('test-multiple-components') e.load() components = dict( (host, list(sorted(c.name for c in e.root_dependencies(host=host)))) for host in sorted(e.hosts.keys())) assert components == dict(localhost=['hello1', 'hello2'], otherhost=['hello3', 'hello4'], thishost=['hello5', 'hello6'])
def test_load_ignores_predefined_environment_settings(sample_service): e = Environment("test-with-env-config") e.service_user = "******" e.host_domain = "sample.com" e.branch = "default" e.load() assert e.service_user == "bob" assert e.host_domain == "sample.com" assert e.branch == "default"
def test_remotehost_start(sample_service): env = Environment("test-with-env-config") env.load() env.configure() h = RemoteHost("asdf", env) h.connect = mock.Mock() h.rpc = mock.Mock() h.rpc.ensure_base.return_value = '/tmp' h.start()
def test_remotehost_start(sample_service): env = Environment("test-with-env-config") env.load() env.configure() d = Deployment(env, platform="", jobs=1, timeout=30, dirty=False) h = RemoteHost("asdf", env) h.connect = mock.Mock() h.rpc = mock.Mock() h.rpc.ensure_base.return_value = '/tmp' h.start()
def test_multiple_components(sample_service): e = Environment("test-multiple-components") e.load() components = dict( (host, list(sorted(c.name for c in e.root_dependencies(host=host)))) for host in sorted(e.hosts.keys())) assert components == dict( localhost=["hello1", "hello2"], otherhost=["hello3", "hello4"], thishost=["hello5", "hello6"], )
def test_components_for_host_can_be_retrieved_from_environment(sample_service): e = Environment("test-overlapping-components") e.load() def _get_components(hostname): return sorted(e.components_for(host=e.hosts[hostname]).keys()) assert ["hello1", "hello2"] == _get_components("localhost") assert ["hello3"] == _get_components("other") assert ["hello2", "hello3"] == _get_components("this") localhost = e.hosts["localhost"] assert "hello1" in localhost.components assert "hello2" in localhost.components assert "hello3" not in localhost.components
def test_components_for_host_can_be_retrieved_from_environment(sample_service): e = Environment('test-overlapping-components') e.load() def _get_components(hostname): return sorted(e.components_for(host=e.hosts[hostname]).keys()) assert ['hello1', 'hello2'] == _get_components('localhost') assert ['hello3'] == _get_components('other') assert ['hello2', 'hello3'] == _get_components('this') localhost = e.hosts['localhost'] assert 'hello1' in localhost.components assert 'hello2' in localhost.components assert 'hello3' not in localhost.components
def test_load_should_use_config(sample_service): e = Environment('test-with-env-config') e.load() assert e.service_user == 'joe' assert e.host_domain == 'example.com' assert e.branch == 'release'
def test_loads_configures_vfs_sandbox(sample_service): e = Environment("test-with-vfs-sandbox") e.load() assert e.vfs_sandbox.map("/asdf").endswith("work/_/asdf") assert e.map("/asdf").endswith("work/_/asdf")
def test_load_sets_up_overrides(sample_service): e = Environment("test-with-overrides") e.load() assert e.overrides == {"hello1": {"asdf": "1"}}
def test_load_should_use_defaults(sample_service): e = Environment('test-without-env-config') e.load() assert e.host_domain is None assert e.branch is None
def test_parse_nonexisting_environment_raises_error(tmpdir): environment = Environment("test", basedir=str(tmpdir)) with pytest.raises(MissingEnvironment): environment.load()
def test_load_sets_up_overrides(sample_service): e = Environment('test-with-overrides') e.load() assert e.overrides == {'hello1': {'asdf': '1'}}
def test_environment_should_raise_if_no_config_file(tmpdir): e = Environment('foobar') with pytest.raises(batou.MissingEnvironment): e.load()
def test_loads_configures_vfs_sandbox(sample_service): e = Environment('test-with-vfs-sandbox') e.load() assert e.vfs_sandbox.map('/asdf').endswith('work/_/asdf') assert e.map('/asdf').endswith('work/_/asdf')
def env(): environment = Environment( "dev", basedir=os.path.dirname(__file__) + "/fixture/basic_service") environment.load() return environment
def env_prod(): environment = Environment('production', basedir=os.path.dirname(__file__) + '/fixture/basic_service') environment.load() return environment