def test_dcos_config_missing_variable(tmp_path): """ Templating fails if a parameter is not set. """ root_path = tmp_path / 'root' values = { 'windows_dcos_install_path': str(root_path), 'provider': 'aws', } dcos_config_path = tmp_path / 'dcos-config-windows.yaml' dcos_config_path.write_text(_DCOS_CONFIG) template = cmdconf.CmdConfigSetup.load_dcos_conf_template(dcos_config_path) dcos_conf = {'template': template, 'values': values} inst_storage = storage.InstallationStorage(root_dpath=str(tmp_path / 'root')) cluster_conf = None setup = command.CmdSetup( command_name='test', dcos_conf=dcos_conf, cluster_conf=cluster_conf, inst_storage=inst_storage, ) with pytest.raises(tmpl.UnsetParameter): setup._deploy_dcos_conf()
def test_command_detect_state(self, tmp_path: Path): """ winpanda setup command fails if a state file is found, indicating that a previous setup/upgrade has failed. """ cmd = command.CmdSetup( command_name='test', command_target='pkgall', inst_storage=storage.InstallationStorage(root_dpath=str(tmp_path / 'root')), ) existing_state = 'RanDOm' cmd.state.set_state(existing_state) # Installation fails due to existing state with pytest.raises(exceptions.InstallationError) as e: cmd.execute() # Error message mentions found state assert existing_state in e.value.args[0]
def test_command_detect_cluster(self, tmp_path: Path): """ winpanda start command fails if a valid cluster is not found. """ cmd = command.CmdStart( command_name='test', command_target='pkgall', inst_storage=storage.InstallationStorage(root_dpath=str(tmp_path / 'root')), ) bindir = tmp_path / 'root' / 'bin' bindir.mkdir(parents=True) mesos_exe = bindir / 'mesos-agent.exe' # Installation fails due to non-existing bindir with pytest.raises(exceptions.InstallationError) as e: cmd.execute() # Error message mentions Mesos agent path assert str(mesos_exe) in e.value.args[0]
def test_command_detect_cluster(self, tmp_path: Path): """ winpanda setup command fails if an existing cluster is found, indicating that a previous setup has installed files. """ cmd = command.CmdSetup( command_name='test', command_target='pkgall', inst_storage=storage.InstallationStorage(root_dpath=str(tmp_path / 'root')), ) bindir = tmp_path / 'root' / 'bin' bindir.mkdir(parents=True) mesos_exe = bindir / 'mesos-agent.exe' mesos_exe.write_text('fake') # Installation fails due to existing cluster with pytest.raises(exceptions.InstallationError) as e: cmd.execute() # Error message mentions mesos-agent.exe assert str(mesos_exe) in e.value.args[0]
def test_dcos_config_ok(tmp_path): """ Files are templated and indented according to YAML. """ root_path = tmp_path / 'root' values = { 'windows_dcos_install_path': str(root_path), 'color': 'red', 'provider': 'aws', 'escaped': '"true"', } dcos_config_path = tmp_path / 'dcos-config-windows.yaml' dcos_config_path.write_text(_DCOS_CONFIG) template = cmdconf.CmdConfigSetup.load_dcos_conf_template(dcos_config_path) dcos_conf = {'template': template, 'values': values} inst_storage = storage.InstallationStorage(root_dpath=str(tmp_path / 'root')) cluster_conf = None setup = command.CmdSetup( command_name='test', dcos_conf=dcos_conf, cluster_conf=cluster_conf, inst_storage=inst_storage, ) setup._deploy_dcos_conf() file1_path = root_path / 'file1.txt' file2_path = root_path / 'subdir' / 'file2.json' assert file1_path.exists() assert file2_path.exists() assert file1_path.read_text() == _FILE1_CONTENTS assert file2_path.read_text() == _FILE2_CONTENTS
def test_dcos_config_aws(tmp_path): """ First replacement is used. """ root_path = tmp_path / 'root' values = { 'windows_dcos_install_path': str(root_path), 'color': 'red', 'provider': 'aws', 'escaped': '"true"', } dcos_config_path = tmp_path / 'dcos-config-windows.yaml' dcos_config_path.write_text(_DCOS_CONFIG_SWITCH) template = cmdconf.CmdConfigSetup.load_dcos_conf_template(dcos_config_path) dcos_conf = {'template': template, 'values': values} inst_storage = storage.InstallationStorage(root_dpath=str(tmp_path / 'root')) cluster_conf = None setup = command.CmdSetup( command_name='test', dcos_conf=dcos_conf, cluster_conf=cluster_conf, inst_storage=inst_storage, ) command._deploy_dcos_conf(setup.config.dcos_conf) file1_path = root_path / 'file1.txt' file2_path = root_path / 'file2.txt' assert file1_path.exists() assert file2_path.exists() assert file1_path.read_text() == 'red' assert file2_path.read_text() == _FILE2_CONTENTS_AWS