Exemplo n.º 1
0
    def test_migration_to_labels(self):
        # Trying to get the container list raises an exception

        with self.assertRaises(legacy.LegacyContainersError) as cm:
            self.project.containers(stopped=True)

        self.assertEqual(
            set(cm.exception.names),
            set([
                'composetest_db_1', 'composetest_web_1', 'composetest_nginx_1'
            ]),
        )

        self.assertEqual(
            set(cm.exception.one_off_names),
            set(['composetest_db_run_1']),
        )

        # Migrate the containers

        legacy.migrate_project_to_labels(self.project)

        # Getting the list no longer raises an exception

        containers = self.project.containers(stopped=True)
        self.assertEqual(len(containers), len(self.services))
Exemplo n.º 2
0
    def test_migration_to_labels(self):
        with mock.patch.object(legacy, 'log', autospec=True) as mock_log:
            self.assertEqual(self.project.containers(stopped=True), [])
            self.assertEqual(mock_log.warn.call_count, len(self.services))

        legacy.migrate_project_to_labels(self.project)
        self.assertEqual(len(self.project.containers(stopped=True)), len(self.services))
Exemplo n.º 3
0
    def test_migration_to_labels(self):
        with self.assertRaises(legacy.LegacyContainersError) as cm:
            self.assertEqual(self.project.containers(stopped=True), [])

        self.assertEqual(
            set(cm.exception.names),
            set(['composetest_db_1', 'composetest_web_1', 'composetest_nginx_1']),
        )

        legacy.migrate_project_to_labels(self.project)
        self.assertEqual(len(self.project.containers(stopped=True)), len(self.services))
Exemplo n.º 4
0
    def test_migration_to_labels(self):
        with self.assertRaises(legacy.LegacyContainersError) as cm:
            self.assertEqual(self.project.containers(stopped=True), [])

        self.assertEqual(
            set(cm.exception.names),
            set([
                'composetest_db_1', 'composetest_web_1', 'composetest_nginx_1'
            ]),
        )

        legacy.migrate_project_to_labels(self.project)
        self.assertEqual(len(self.project.containers(stopped=True)),
                         len(self.services))
Exemplo n.º 5
0
    def test_migration_one_off(self):
        # We've already migrated

        legacy.migrate_project_to_labels(self.project)

        # Trying to create a one-off container results in a Docker API error

        with self.assertRaises(APIError) as cm:
            self.project.get_service('db').create_container(one_off=True)

        # Checking for legacy one-off containers raises an exception

        with self.assertRaises(legacy.LegacyOneOffContainersError) as cm:
            legacy.check_for_legacy_containers(
                self.client,
                self.project.name,
                ['db'],
                allow_one_off=False,
            )

        self.assertEqual(
            set(cm.exception.one_off_names),
            set(['composetest_db_run_1']),
        )

        # Remove the old one-off container

        c = self.client.inspect_container('composetest_db_run_1')
        self.client.remove_container(c)

        # Checking no longer raises an exception

        legacy.check_for_legacy_containers(
            self.client,
            self.project.name,
            ['db'],
            allow_one_off=False,
        )

        # Creating a one-off container no longer results in an API error

        self.project.get_service('db').create_container(one_off=True)
        self.assertIsInstance(
            self.client.inspect_container('composetest_db_run_1'), dict)
Exemplo n.º 6
0
    def test_migration_one_off(self):
        # We've already migrated

        legacy.migrate_project_to_labels(self.project)

        # Trying to create a one-off container results in a Docker API error

        with self.assertRaises(APIError) as cm:
            self.project.get_service('db').create_container(one_off=True)

        # Checking for legacy one-off containers raises an exception

        with self.assertRaises(legacy.LegacyOneOffContainersError) as cm:
            legacy.check_for_legacy_containers(
                self.client,
                self.project.name,
                ['db'],
                allow_one_off=False,
            )

        self.assertEqual(
            set(cm.exception.one_off_names),
            set(['composetest_db_run_1']),
        )

        # Remove the old one-off container

        c = self.client.inspect_container('composetest_db_run_1')
        self.client.remove_container(c)

        # Checking no longer raises an exception

        legacy.check_for_legacy_containers(
            self.client,
            self.project.name,
            ['db'],
            allow_one_off=False,
        )

        # Creating a one-off container no longer results in an API error

        self.project.get_service('db').create_container(one_off=True)
        self.assertIsInstance(self.client.inspect_container('composetest_db_run_1'), dict)
Exemplo n.º 7
0
    def test_migration_to_labels(self):
        # Trying to get the container list raises an exception

        with self.assertRaises(legacy.LegacyContainersError) as cm:
            self.project.containers(stopped=True)

        self.assertEqual(
            set(cm.exception.names),
            set(['composetest_db_1', 'composetest_web_1', 'composetest_nginx_1']),
        )

        self.assertEqual(
            set(cm.exception.one_off_names),
            set(['composetest_db_run_1']),
        )

        # Migrate the containers

        legacy.migrate_project_to_labels(self.project)

        # Getting the list no longer raises an exception

        containers = self.project.containers(stopped=True)
        self.assertEqual(len(containers), len(self.services))