Exemplo n.º 1
0
    def test_docker_host_tags_ok(self):
        du = DockerUtil()
        mock_isswarm = mock.MagicMock(name='is_swarm', return_value=False)
        du._client = mock.MagicMock()
        du.is_swarm = mock_isswarm

        self.assertEqual([], DockerUtil().get_host_tags())
Exemplo n.º 2
0
    def test_image_name_from_image_repodigests(self):
        du = DockerUtil()
        du._client = mock.MagicMock()
        du._client.inspect_image = mock.MagicMock(name='inspect_image', return_value = {'RepoTags': [],
            'RepoDigests': ['alpine@sha256:4f2d8bbad359e3e6f23c0498e009aaa3e2f31996cbea7269b78f92ee43647811']})

        co = {'Image': 'sha256:e48e77eee11b6d9ac9fc35a23992b4158355a8ec3fd3725526eba3f467e4b6d9'}
        self.assertEqual('alpine', du.image_name_extractor(co))
Exemplo n.º 3
0
 def test_docker_host_metadata_invalid_response(self):
     mock_version = mock.MagicMock(name='version', return_value=None)
     du = DockerUtil()
     du._client = mock.MagicMock()
     du._client.version = mock_version
     du.swarm_node_state = 'inactive'
     self.assertEqual({'docker_swarm': 'inactive'}, DockerUtil().get_host_metadata())
     mock_version.assert_called_once()
Exemplo n.º 4
0
 def test_docker_host_metadata_ok(self):
     mock_version = mock.MagicMock(name='version', return_value={'Version': '1.13.1'})
     du = DockerUtil()
     du._client = mock.MagicMock()
     du._client.version = mock_version
     du.swarm_node_state = 'inactive'
     self.assertEqual({'docker_version': '1.13.1', 'docker_swarm': 'inactive'}, du.get_host_metadata())
     mock_version.assert_called_once()
Exemplo n.º 5
0
 def test_docker_host_metadata_invalid_response(self):
     mock_version = mock.MagicMock(name='version', return_value=None)
     du = DockerUtil()
     du._client = mock.MagicMock()
     du._client.version = mock_version
     du.swarm_node_state = 'inactive'
     self.assertEqual({'docker_swarm': 'inactive'}, DockerUtil().get_host_metadata())
     mock_version.assert_called_once()
Exemplo n.º 6
0
    def test_image_name_from_image_repodigests(self):
        du = DockerUtil()
        du._client = mock.MagicMock()
        du._client.inspect_image = mock.MagicMock(name='inspect_image', return_value = {'RepoTags': [],
            'RepoDigests': ['alpine@sha256:4f2d8bbad359e3e6f23c0498e009aaa3e2f31996cbea7269b78f92ee43647811']})

        co = {'Image': 'sha256:e48e77eee11b6d9ac9fc35a23992b4158355a8ec3fd3725526eba3f467e4b6d9'}
        self.assertEqual('alpine', du.image_name_extractor(co))
Exemplo n.º 7
0
 def test_docker_host_metadata_ok(self):
     mock_version = mock.MagicMock(name='version', return_value={'Version': '1.13.1'})
     du = DockerUtil()
     du._client = mock.MagicMock()
     du._client.version = mock_version
     du.swarm_node_state = 'inactive'
     self.assertEqual({'docker_version': '1.13.1', 'docker_swarm': 'inactive'}, du.get_host_metadata())
     mock_version.assert_called_once()
Exemplo n.º 8
0
    def test_docker_host_metadata_swarm_ok(self):
        du = DockerUtil()
        mock_version = mock.MagicMock(name='version', return_value={'Version': '1.13.1'})
        mock_isswarm = mock.MagicMock(name='is_swarm', return_value=True)
        du._client = mock.MagicMock()
        du._client.version = mock_version
        du.is_swarm = mock_isswarm

        self.assertEqual({'docker_version': '1.13.1', 'docker_swarm': 'active'}, DockerUtil().get_host_metadata())
        mock_version.assert_called_once()
Exemplo n.º 9
0
    def test_docker_host_tags_swarm_ok(self):
        du = DockerUtil()
        mock_info = mock.MagicMock(name='info', return_value={'Swarm': {'ControlAvailable' : True}})
        mock_isswarm = mock.MagicMock(name='is_swarm', return_value=True)
        du._client = mock.MagicMock()
        du._client.info = mock_info
        du.is_swarm = mock_isswarm

        self.assertEqual(['docker_swarm_node_role:manager'], DockerUtil().get_host_tags())
        mock_info.assert_called_once()
Exemplo n.º 10
0
    def test_docker_host_metadata_swarm_ok(self):
        du = DockerUtil()
        mock_version = mock.MagicMock(name='version', return_value={'Version': '1.13.1'})
        mock_isswarm = mock.MagicMock(name='is_swarm', return_value=True)
        du._client = mock.MagicMock()
        du._client.version = mock_version
        du.is_swarm = mock_isswarm

        self.assertEqual({'docker_version': '1.13.1', 'docker_swarm': 'active'}, DockerUtil().get_host_metadata())
        mock_version.assert_called_once()
Exemplo n.º 11
0
    def test_auto_inspect(self):
        du = DockerUtil()
        du._client = mock.MagicMock()
        mock_inspect = mock.MagicMock(name='inspect_container', return_value = {'RepoTags': ["redis:3.2"], 'RepoDigests': []})
        du._client.inspect_container = mock_inspect

        dummy = self.NeedLabelsUtil()
        dummy.reset_cache()

        dummy.get_container_tags(cid=CO_ID)
        mock_inspect.assert_called_once()
Exemplo n.º 12
0
    def test_image_name_from_image_repotags(self):
        du = DockerUtil()
        du._client = mock.MagicMock()
        mock_img = mock.MagicMock(name='inspect_image', return_value = {'RepoTags': ["redis:3.2"], 'RepoDigests': []})
        du._client.inspect_image = mock_img
        sha = 'sha256:e48e77eee11b6d9ac9fc35a23992b4158355a8ec3fd3725526eba3f467e4b6c9'
        co = {'Image': sha}
        self.assertEqual('redis:3.2', DockerUtil().image_name_extractor(co))
        mock_img.assert_called_once_with(sha)

        # Make sure cache is used insead of call again inspect_image
        DockerUtil().image_name_extractor(co)
        mock_img.assert_called_once()
Exemplo n.º 13
0
    def test_image_name_from_image_repotags(self):
        du = DockerUtil()
        du._client = mock.MagicMock()
        mock_img = mock.MagicMock(name='inspect_image', return_value = {'RepoTags': ["redis:3.2"], 'RepoDigests': []})
        du._client.inspect_image = mock_img
        sha = 'sha256:e48e77eee11b6d9ac9fc35a23992b4158355a8ec3fd3725526eba3f467e4b6c9'
        co = {'Image': sha}
        self.assertEqual('redis:3.2', DockerUtil().image_name_extractor(co))
        mock_img.assert_called_once_with(sha)

        # Make sure cache is used insead of call again inspect_image
        DockerUtil().image_name_extractor(co)
        mock_img.assert_called_once()
    def test_auto_inspect(self):
        du = DockerUtil()
        du._client = mock.MagicMock()
        mock_inspect = mock.MagicMock(name='inspect_container',
                                      return_value={
                                          'RepoTags': ["redis:3.2"],
                                          'RepoDigests': []
                                      })
        du._client.inspect_container = mock_inspect

        dummy = self.NeedLabelsUtil()
        dummy.reset_cache()

        dummy.get_container_tags(cid=CO_ID)
        mock_inspect.assert_called_once()