"Fossies" - the Fresh Open Source Software Archive

Member "salt-3002.2/tests/integration/ssh/test_pre_flight.py" (18 Nov 2020, 2488 Bytes) of package /linux/misc/salt-3002.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "test_pre_flight.py": 3002.1_vs_3002.2.

    1 """
    2 Test for ssh_pre_flight roster option
    3 """
    4 
    5 import os
    6 
    7 import salt.utils.files
    8 from tests.support.case import SSHCase
    9 from tests.support.helpers import slowTest
   10 from tests.support.runtests import RUNTIME_VARS
   11 
   12 
   13 class SSHPreFlightTest(SSHCase):
   14     """
   15     Test ssh_pre_flight roster option
   16     """
   17 
   18     def setUp(self):
   19         super().setUp()
   20         self.roster = os.path.join(RUNTIME_VARS.TMP, "pre_flight_roster")
   21         self.data = {
   22             "ssh_pre_flight": os.path.join(RUNTIME_VARS.TMP, "ssh_pre_flight.sh")
   23         }
   24         self.test_script = os.path.join(
   25             RUNTIME_VARS.TMP, "test-pre-flight-script-worked.txt"
   26         )
   27 
   28     def _create_roster(self):
   29         self.custom_roster(self.roster, self.data)
   30 
   31         with salt.utils.files.fopen(self.data["ssh_pre_flight"], "w") as fp_:
   32             fp_.write("touch {}".format(self.test_script))
   33 
   34     @slowTest
   35     def test_ssh_pre_flight(self):
   36         """
   37         test ssh when ssh_pre_flight is set
   38         ensure the script runs successfully
   39         """
   40         self._create_roster()
   41         assert self.run_function("test.ping", roster_file=self.roster)
   42 
   43         assert os.path.exists(self.test_script)
   44 
   45     @slowTest
   46     def test_ssh_run_pre_flight(self):
   47         """
   48         test ssh when --pre-flight is passed to salt-ssh
   49         to ensure the script runs successfully
   50         """
   51         self._create_roster()
   52         # make sure we previously ran a command so the thin dir exists
   53         self.run_function("test.ping", wipe=False)
   54         assert not os.path.exists(self.test_script)
   55 
   56         assert self.run_function(
   57             "test.ping", ssh_opts="--pre-flight", roster_file=self.roster, wipe=False
   58         )
   59         assert os.path.exists(self.test_script)
   60 
   61     @slowTest
   62     def test_ssh_run_pre_flight_failure(self):
   63         """
   64         test ssh_pre_flight when there is a failure
   65         in the script.
   66         """
   67         self._create_roster()
   68         with salt.utils.files.fopen(self.data["ssh_pre_flight"], "w") as fp_:
   69             fp_.write("exit 2")
   70 
   71         ret = self.run_function(
   72             "test.ping", ssh_opts="--pre-flight", roster_file=self.roster, wipe=False
   73         )
   74         assert ret["retcode"] == 2
   75 
   76     def tearDown(self):
   77         """
   78         make sure to clean up any old ssh directories
   79         """
   80         files = [self.roster, self.data["ssh_pre_flight"], self.test_script]
   81         for fp_ in files:
   82             if os.path.exists(fp_):
   83                 os.remove(fp_)