コード例 #1
0
ファイル: test_agent.py プロジェクト: brennentsmith/teletraan
 def test_get_build_id(self):
     """
      Test get_build_id method 
     """
     self.assertEqual(Helper.get_build_id("cmp_test-r4TTZfrWQEmgyaYic8uU6w_8ef9007.tar.gz", "cmp_test")[1],
         "r4TTZfrWQEmgyaYic8uU6w_8ef9007")
     self.assertEqual(Helper.get_build_id("cmp_test-r4TTZfrWQEmgyaYic8uU6w_8ef9007.zip", "cmp_test")[1],
         "r4TTZfrWQEmgyaYic8uU6w_8ef9007")
     self.assertFalse(Helper.get_build_id("whateverfile", "cmp_test")[0])
     self.assertFalse(Helper.get_build_id("whateverfile.tar.gz", "cmp_test")[0])
     self.assertFalse(Helper.get_build_id("cmp_test-tmp", "cmp_test")[0])
コード例 #2
0
ファイル: test_agent.py プロジェクト: brennentsmith/teletraan
 def test_builds_available_locally(self):
     """This uses the filesystem."""
     config = mock.Mock()
     config.get_var = mock.Mock(return_value=self.builds_dir)
     helper = Helper(config)
     self.assertEqual([], helper.builds_available_locally(self.builds_dir,'fakeenv'))
     open(os.path.join(self.builds_dir, 'fakeenv-fakebuild.tar.gz'),'a').close()
     # builds_available_locally returns a tuple with buildname and timestamp.
     # let's just look at buildname
     self.assertEqual('fakebuild',
                      helper.builds_available_locally(self.builds_dir,'fakeenv')[0][0])
コード例 #3
0
ファイル: test_agent.py プロジェクト: zhangjianTFTC/teletraan
 def test_builds_available_locally(self):
     """This uses the filesystem."""
     config = mock.Mock()
     config.get_var = mock.Mock(return_value=self.builds_dir)
     self.assertEqual([],
                      Helper(config).builds_available_locally(
                          self.builds_dir))
     os.mkdir(os.path.join(self.builds_dir, 'fakebuild'))
     # builds_available_locally returns a tuple with buildname and timestamp.
     # let's just look at buildname
     self.assertEqual(
         'fakebuild',
         Helper(config).builds_available_locally(self.builds_dir)[0][0])
コード例 #4
0
 def test_builds_available_locally(self):
     """This uses the filesystem."""
     config = mock.Mock()
     config.get_var = mock.Mock(return_value=self.builds_dir)
     helper = Helper(config)
     self.assertEqual([],
                      helper.builds_available_locally(
                          self.builds_dir, 'fakeenv'))
     open(os.path.join(self.builds_dir, 'fakeenv-fakebuild.tar.gz'),
          'a').close()
     # builds_available_locally returns a tuple with buildname and timestamp.
     # let's just look at buildname
     self.assertEqual(
         'fakebuild',
         helper.builds_available_locally(self.builds_dir, 'fakeenv')[0][0])
コード例 #5
0
 def test_get_build_id(self):
     """
      Test get_build_id method 
     """
     self.assertEqual(
         Helper.get_build_id(
             "cmp_test-r4TTZfrWQEmgyaYic8uU6w_8ef9007.tar.gz",
             "cmp_test")[1], "r4TTZfrWQEmgyaYic8uU6w_8ef9007")
     self.assertEqual(
         Helper.get_build_id("cmp_test-r4TTZfrWQEmgyaYic8uU6w_8ef9007.zip",
                             "cmp_test")[1],
         "r4TTZfrWQEmgyaYic8uU6w_8ef9007")
     self.assertFalse(Helper.get_build_id("whateverfile", "cmp_test")[0])
     self.assertFalse(
         Helper.get_build_id("whateverfile.tar.gz", "cmp_test")[0])
     self.assertFalse(Helper.get_build_id("cmp_test-tmp", "cmp_test")[0])
コード例 #6
0
    def test_get_stale_builds(self):
        """Test the ``get_stale_builds`` method.

        Make sure that we: Return nor more than n-m builds.  Where n is
        ``len(build_timestamps)`` and m is ``num_builds_to_retain``.
        """
        def check_stale_build(build_timestamps, expected_total):
            num_builds = len(list(Helper.get_stale_builds(build_timestamps,
                                                          2)))
            self.assertEqual(expected_total, num_builds)

        # Test no results for 0 builds, ``num_builds_to_retain=2``.
        check_stale_build([], 0)

        # Test no results for 1 builds, ``num_builds_to_retain=2``.
        check_stale_build([('abuild', 1)], 0)

        # Test no results for 2 builds, ``num_builds_to_retain=2``.
        check_stale_build([('abuild', 1)] * 2, 0)

        # Test 1 results for 3 builds, ``num_builds_to_retain=2``.
        check_stale_build([('abuild', 1)] * 3, 1)

        # Test 5 results for 7 builds, ``num_builds_to_retain=2``
        check_stale_build([('abuild', 1)] * 7, 5)

        # verify oldest build got returned first
        time1 = time.time()  # time now
        time2 = time1 - 10  # 10s ago
        time3 = time2 - 10  # 10 more seconds ago
        self.assertEqual(
            list(
                Helper.get_stale_builds([('abuild', time1), ('abuild2', time2),
                                         ('abuild3', time3)], 2)), ['abuild3'])
コード例 #7
0
ファイル: test_agent.py プロジェクト: DomenZero/teletraan
 def check_stale_build(build_timestamps, expected_total):
     num_builds = len(
         list(
             Helper.get_stale_builds(
                 build_timestamps,
                 2)))
     self.assertEqual(expected_total, num_builds)
コード例 #8
0
 def __init__(self, client, estatus=None, conf=None, executor=None, helper=None):
     self._response = None
     # a map maintains env_name -> deploy_status
     self._envs = {}
     self._config = conf or Config()
     self._executor = executor
     self._helper = helper or Helper(self._config)
     self._STATUS_FILE = self._config.get_env_status_fn()
     self._client = client
     self._env_status = estatus or EnvStatus(self._STATUS_FILE)
     # load environment deploy status file from local disk
     self.load_status_file()
コード例 #9
0
ファイル: test_agent.py プロジェクト: DomenZero/teletraan
    def test_get_stale_builds(self):
        """Test the ``get_stale_builds`` method.

        Make sure that we: Return nor more than n-m builds.  Where n is
        ``len(build_timestamps)`` and m is ``num_builds_to_retain``.
        """
        def check_stale_build(build_timestamps, expected_total):
            num_builds = len(
                list(
                    Helper.get_stale_builds(
                        build_timestamps,
                        2)))
            self.assertEqual(expected_total, num_builds)

        # Test no results for 0 builds, ``num_builds_to_retain=2``.
        check_stale_build([], 0)

        # Test no results for 1 builds, ``num_builds_to_retain=2``.
        check_stale_build([('abuild', 1)], 0)

        # Test no results for 2 builds, ``num_builds_to_retain=2``.
        check_stale_build([('abuild', 1)] * 2, 0)

        # Test 1 results for 3 builds, ``num_builds_to_retain=2``.
        check_stale_build([('abuild', 1)] * 3, 1)

        # Test 5 results for 7 builds, ``num_builds_to_retain=2``
        check_stale_build([('abuild', 1)] * 7, 5)

        # verify oldest build got returned first
        time1 = time.time()  # time now
        time2 = time1 - 10  # 10s ago
        time3 = time2 - 10  # 10 more seconds ago
        self.assertEqual(list(
            Helper.get_stale_builds(
                [('abuild', time1), ('abuild2', time2), ('abuild3', time3)],
                2)), ['abuild3'])
コード例 #10
0
ファイル: test_helper.py プロジェクト: zmyer/teletraan
    def setUpClass(cls):
        cls.base_dir = tempfile.mkdtemp()
        builds_dir = os.path.join(cls.base_dir, 'builds')
        target = os.path.join(cls.base_dir, 'test')
        cls.target = target
        cls.builds_dir = builds_dir
        cls.url = 'https://deployrepo.pinadmin.com/deploy-scripts/'\
                  '24714bcb0927661873c0acf34194d4f51b4da429.tar.gz'

        if not os.path.exists(builds_dir):
            os.mkdir(builds_dir)

        def mock_get_var(var_name):
            if var_name == 'builds_dir':
                return builds_dir
            elif var_name == 'env_directory':
                return cls.base_dir
            elif var_name == 'package_format':
                return 'tar.gz'

        config = mock.Mock()
        config.get_var = mock.MagicMock(side_effect=mock_get_var)
        config.get_target = mock.MagicMock(return_value=target)
        cls.helper = Helper(config)
コード例 #11
0
 def check_stale_build(build_timestamps, expected_total):
     num_builds = len(list(Helper.get_stale_builds(build_timestamps,
                                                   2)))
     self.assertEqual(expected_total, num_builds)