def test_docker_highstate(self): """ check that docker.highstate works, and works with a container not running as root """ top_sls = """ base: '*': - core """ core_state = """ {}/testfile: file: - managed - source: salt://testfile - makedirs: true """.format( RUNTIME_VARS.TMP ) with temp_state_file("top.sls", top_sls), temp_state_file( "core.sls", core_state ): ret = self.run_function("docker.apply", [self.random_name]) self.assertSaltTrueReturn(ret)
def test_lazy_avail_states_other(self): top_sls = """ base: '*': - core """ core_state = """ {}/testfile: file: - managed - source: salt://testfile - makedirs: true """.format(RUNTIME_VARS.TMP) with temp_state_file("{}/top.sls".format( self.base_state_tree_dir), top_sls), temp_state_file( "{}/core.sls".format(self.base_state_tree_dir), core_state): # list_states not called yet self.assertEqual(self.highstate.avail._filled, False) self.assertEqual(self.highstate.avail._avail, {"base": None}) # After getting 'other' env available states self.highstate.avail["other"] # pylint: disable=pointless-statement self.assertEqual(self.highstate.avail._filled, True) self.assertEqual(self.highstate.avail._avail, { "base": None, "other": ["test"] })
def test_show_highstate(self): """ state.show_highstate with salt-ssh """ top_sls = """ base: '*': - core """ core_state = """ {}/testfile: file: - managed - source: salt://testfile - makedirs: true """.format(RUNTIME_VARS.TMP) with temp_state_file("top.sls", top_sls), temp_state_file("core.sls", core_state): high = self.run_function("state.show_highstate") destpath = os.path.join(RUNTIME_VARS.TMP, "testfile") self.assertIsInstance(high, dict) self.assertIn(destpath, high) self.assertEqual(high[destpath]["__env__"], "base")
def test_list_states(self): """ cp.list_states """ top_sls = """ base: '*': - core """ core_state = """ {}/testfile: file: - managed - source: salt://testfile - makedirs: true """.format( RUNTIME_VARS.TMP ) with temp_state_file("top.sls", top_sls), temp_state_file( "core.sls", core_state ): ret = self.run_function("cp.list_states",) self.assertIn("core", ret) self.assertIn("top", ret)
def test_output_highstate(self): """ Regression tests for the highstate outputter. Calls a basic state with various flags. Each comparison should be identical when successful. """ simple_ping_sls = """ simple-ping: module.run: - name: test.ping """ with temp_state_file("simple-ping.sls", simple_ping_sls): # Test basic highstate output. No frills. expected = [ "minion:", " ID: simple-ping", " Function: module.run", " Name: test.ping", " Result: True", " Comment: Module function test.ping executed", " Changes: ", " ret:", " True", "Summary for minion", "Succeeded: 1 (changed=1)", "Failed: 0", "Total states run: 1", ] state_run = self.run_salt('"minion" state.sls simple-ping') for expected_item in expected: self.assertIn(expected_item, state_run) # Test highstate output while also passing --out=highstate. # This is a regression test for Issue #29796 state_run = self.run_salt( '"minion" state.sls simple-ping --out=highstate') for expected_item in expected: self.assertIn(expected_item, state_run) # Test highstate output when passing --static and running a state function. # See Issue #44556. state_run = self.run_salt( '"minion" state.sls simple-ping --static') for expected_item in expected: self.assertIn(expected_item, state_run) # Test highstate output when passing --static and --out=highstate. # See Issue #44556. state_run = self.run_salt( '"minion" state.sls simple-ping --static --out=highstate') for expected_item in expected: self.assertIn(expected_item, state_run)
def test_state_highstate(self): top_sls = """ base: '*': - core """ core_state = """ {}/testfile: file: - managed - source: salt://testfile - makedirs: true """.format(RUNTIME_VARS.TMP) with temp_state_file("top.sls", top_sls), temp_state_file("core.sls", core_state): ret = self.run_function("state.highstate") for key, value in ret.items(): self.assertTrue(value["result"])
def test_state_show_top(self): """ test state.show_top with salt-ssh """ top_sls = """ base: '*': - core """ core_state = """ {}/testfile: file: - managed - source: salt://testfile - makedirs: true """.format(RUNTIME_VARS.TMP) with temp_state_file("top.sls", top_sls), temp_state_file("core.sls", core_state): ret = self.run_function("state.show_top") self.assertEqual(ret, {"base": ["core", "master_tops_test"]})
def test_state_apply(self): core_state = """ {}/testfile: file: - managed - source: salt://testfile - makedirs: true """.format(RUNTIME_VARS.TMP) with temp_state_file("core.sls", core_state): ret = self.run_function("state.apply", ["core"]) for key, value in ret.items(): self.assertTrue(value["result"])
def test_show_lowstate(self): """ state.show_lowstate with salt-ssh """ top_sls = """ base: '*': - core """ core_state = """ {}/testfile: file: - managed - source: salt://testfile - makedirs: true """.format(RUNTIME_VARS.TMP) with temp_state_file("top.sls", top_sls), temp_state_file("core.sls", core_state): low = self.run_function("state.show_lowstate") self.assertIsInstance(low, list) self.assertIsInstance(low[0], dict)
def test_managed_multiple_comps(self): state_file = """ ubuntu-backports: pkgrepo.managed: - name: 'deb http://fi.archive.ubuntu.com/ubuntu focal-backports' - comps: main, restricted, universe, multiverse - refresh: false - disabled: false - clean_file: true - file: /etc/apt/sources.list.d/99-salt-archive-ubuntu-focal-backports.list - require_in: - pkgrepo: canonical-ubuntu canonical-ubuntu: pkgrepo.managed: - name: 'deb http://archive.canonical.com/ubuntu {{ salt['grains.get']('oscodename') }}' - comps: partner - refresh: false - disabled: false - clean_file: true - file: /etc/apt/sources.list.d/99-salt-canonical-ubuntu.list """ def remove_apt_list_file(path): if os.path.exists(path): os.unlink(path) self.addCleanup( remove_apt_list_file, "/etc/apt/sources.list.d/99-salt-canonical-ubuntu.list", ) self.addCleanup( remove_apt_list_file, "/etc/apt/sources.list.d/99-salt-archive-ubuntu-focal-backports.list", ) with temp_state_file("multiple-comps-repos.sls", state_file): ret = self.run_function("state.sls", ["multiple-comps-repos"]) for state_run in ret.values(): # On the first run, we must have changes assert state_run["changes"] ret = self.run_function("state.sls", ["multiple-comps-repos"]) for state_run in ret.values(): # On the second run though, we shouldn't have changes made assert not state_run["changes"]
def test_backends_decode_body_true(self): """ test all backends when using decode_body=True that it returns string and decodes it. """ core_state = """ {}: file: - managed - source: salt://testfile - makedirs: true """.format(RUNTIME_VARS.TMP) with temp_state_file("{}/core.sls".format(self.get_webserver.root), core_state): for backend in ["tornado", "requests", "urllib2"]: ret = http.query(self.get_webserver.url("core.sls"), backend=backend) body = ret.get("body", "") assert isinstance(body, str)