def test_cleanup_apps_dont_kill_everything(self):
        soa_dir = 'not_really_a_dir'
        expected_apps = []
        fake_app_ids = [mock.Mock(id='present.away.gone.wtf'), mock.Mock(id='on-app.off.stop.jrm'),
                        mock.Mock(id='not-here.oh.no.weirdo')]
        self.fake_marathon_client.list_apps = mock.Mock(return_value=fake_app_ids)
        with contextlib.nested(
            mock.patch('paasta_tools.cleanup_marathon_jobs.get_services_for_cluster',
                       return_value=expected_apps, autospec=True),
            mock.patch('paasta_tools.marathon_tools.load_marathon_config',
                       autospec=True,
                       return_value=self.fake_marathon_config),
            mock.patch('paasta_tools.marathon_tools.get_marathon_client', autospec=True,
                       return_value=self.fake_marathon_client),
            mock.patch('paasta_tools.cleanup_marathon_jobs.delete_app', autospec=True),
        ) as (
            get_services_for_cluster_patch,
            config_patch,
            client_patch,
            delete_patch,
        ):
            with raises(cleanup_marathon_jobs.DontKillEverythingError):
                cleanup_marathon_jobs.cleanup_apps(soa_dir)
            config_patch.assert_called_once_with()
            get_services_for_cluster_patch.assert_called_once_with(instance_type='marathon', soa_dir=soa_dir)
            client_patch.assert_called_once_with(self.fake_marathon_config.get_url(),
                                                 self.fake_marathon_config.get_username(),
                                                 self.fake_marathon_config.get_password())

            assert delete_patch.call_count == 0
 def test_cleanup_apps_doesnt_delete_unknown_apps(self):
     soa_dir = 'not_really_a_dir'
     expected_apps = [('present', 'away'), ('on-app', 'off')]
     fake_app_ids = [mock.Mock(id='non_conforming_app')]
     self.fake_marathon_client.list_apps = mock.Mock(
         return_value=fake_app_ids)
     with contextlib.nested(
             mock.patch(
                 'paasta_tools.cleanup_marathon_jobs.get_services_for_cluster',
                 return_value=expected_apps,
                 autospec=True),
             mock.patch('paasta_tools.marathon_tools.load_marathon_config',
                        autospec=True,
                        return_value=self.fake_marathon_config),
             mock.patch('paasta_tools.marathon_tools.get_marathon_client',
                        autospec=True,
                        return_value=self.fake_marathon_client),
             mock.patch('paasta_tools.cleanup_marathon_jobs.delete_app',
                        autospec=True),
     ) as (
             get_services_for_cluster_patch,
             config_patch,
             client_patch,
             delete_patch,
     ):
         cleanup_marathon_jobs.cleanup_apps(soa_dir)
         assert delete_patch.call_count == 0
 def test_cleanup_apps_force(self):
     soa_dir = 'not_really_a_dir'
     expected_apps = []
     fake_app_ids = [
         mock.Mock(id='present.away.gone.wtf'),
         mock.Mock(id='on-app.off.stop.jrm'),
         mock.Mock(id='not-here.oh.no.weirdo')
     ]
     self.fake_marathon_client.list_apps = mock.Mock(
         return_value=fake_app_ids)
     with mock.patch(
             'paasta_tools.cleanup_marathon_jobs.get_services_for_cluster',
             return_value=expected_apps,
             autospec=True,
     ) as get_services_for_cluster_patch, mock.patch(
             'paasta_tools.marathon_tools.load_marathon_config',
             autospec=True,
             return_value=self.fake_marathon_config,
     ) as config_patch, mock.patch(
             'paasta_tools.marathon_tools.get_marathon_client',
             autospec=True,
             return_value=self.fake_marathon_client,
     ) as client_patch, mock.patch(
             'paasta_tools.cleanup_marathon_jobs.delete_app',
             autospec=True,
     ) as delete_patch:
         cleanup_marathon_jobs.cleanup_apps(soa_dir, force=True)
         config_patch.assert_called_once_with()
         get_services_for_cluster_patch.assert_called_once_with(
             instance_type='marathon', soa_dir=soa_dir)
         client_patch.assert_called_once_with(
             self.fake_marathon_config.get_url(),
             self.fake_marathon_config.get_username(),
             self.fake_marathon_config.get_password())
         assert delete_patch.call_count == 3
Beispiel #4
0
    def test_cleanup_apps_dont_kill_everything(self):
        soa_dir = "not_really_a_dir"
        expected_apps = []
        fake_app_ids = [
            mock.Mock(id="present.away.gone.wtf"),
            mock.Mock(id="on-app.off.stop.jrm"),
            mock.Mock(id="not-here.oh.no.weirdo"),
        ]
        self.fake_marathon_client.list_apps = mock.Mock(
            return_value=fake_app_ids)
        with mock.patch(
                "paasta_tools.cleanup_marathon_jobs.get_services_for_cluster",
                return_value=expected_apps,
                autospec=True,
        ) as get_services_for_cluster_patch, mock.patch(
                "paasta_tools.cleanup_marathon_jobs.load_system_paasta_config",
                autospec=True,
                return_value=self.fake_system_config,
        ) as config_patch, mock.patch(
                "paasta_tools.marathon_tools.get_marathon_clients",
                autospec=True,
                return_value=self.fake_marathon_clients,
        ) as clients_patch, mock.patch(
                "paasta_tools.cleanup_marathon_jobs.delete_app",
                autospec=True) as delete_patch:
            with raises(cleanup_marathon_jobs.DontKillEverythingError):
                cleanup_marathon_jobs.cleanup_apps(soa_dir)
            config_patch.assert_called_once_with()
            get_services_for_cluster_patch.assert_called_once_with(
                instance_type="marathon", soa_dir=soa_dir)
            clients_patch.assert_called_once_with(mock.ANY)

            assert delete_patch.call_count == 0
 def test_cleanup_apps_doesnt_delete_unknown_apps(self):
     soa_dir = 'not_really_a_dir'
     expected_apps = [('present', 'away'), ('on-app', 'off')]
     fake_app_ids = [mock.Mock(id='non_conforming_app')]
     self.fake_marathon_client.list_apps = mock.Mock(return_value=fake_app_ids)
     with contextlib.nested(
         mock.patch('paasta_tools.cleanup_marathon_jobs.get_services_for_cluster',
                    return_value=expected_apps, autospec=True),
         mock.patch('paasta_tools.marathon_tools.load_marathon_config',
                    autospec=True,
                    return_value=self.fake_marathon_config),
         mock.patch('paasta_tools.marathon_tools.get_marathon_client', autospec=True,
                    return_value=self.fake_marathon_client),
         mock.patch('paasta_tools.cleanup_marathon_jobs.delete_app', autospec=True),
     ) as (
         get_services_for_cluster_patch,
         config_patch,
         client_patch,
         delete_patch,
     ):
         cleanup_marathon_jobs.cleanup_apps(soa_dir)
         assert delete_patch.call_count == 0
Beispiel #6
0
 def test_cleanup_apps_doesnt_delete_unknown_apps(self):
     soa_dir = "not_really_a_dir"
     expected_apps = [("present", "away"), ("on-app", "off")]
     fake_app_ids = [mock.Mock(id="non_conforming_app")]
     self.fake_marathon_client.list_apps = mock.Mock(
         return_value=fake_app_ids)
     with mock.patch(
             "paasta_tools.cleanup_marathon_jobs.get_services_for_cluster",
             return_value=expected_apps,
             autospec=True,
     ), mock.patch(
             "paasta_tools.cleanup_marathon_jobs.load_system_paasta_config",
             autospec=True,
             return_value=self.fake_system_config,
     ), mock.patch(
             "paasta_tools.marathon_tools.get_marathon_clients",
             autospec=True,
             return_value=self.fake_marathon_clients,
     ), mock.patch("paasta_tools.cleanup_marathon_jobs.delete_app",
                   autospec=True) as delete_patch:
         cleanup_marathon_jobs.cleanup_apps(soa_dir)
         assert delete_patch.call_count == 0
Beispiel #7
0
 def test_cleanup_apps(self):
     soa_dir = 'not_really_a_dir'
     expected_apps = [('present', 'away'), ('on-app', 'off')]
     fake_app_ids = [
         mock.Mock(id='present.away.gone.wtf'),
         mock.Mock(id='on-app.off.stop.jrm'),
         mock.Mock(id='not-here.oh.no.weirdo'),
     ]
     self.fake_marathon_client.list_apps = mock.Mock(
         return_value=fake_app_ids)
     with mock.patch(
             'paasta_tools.cleanup_marathon_jobs.get_services_for_cluster',
             return_value=expected_apps,
             autospec=True,
     ) as get_services_for_cluster_patch, mock.patch(
             'paasta_tools.cleanup_marathon_jobs.load_system_paasta_config',
             autospec=True,
             return_value=self.fake_system_config,
     ) as config_patch, mock.patch(
             'paasta_tools.marathon_tools.get_marathon_clients',
             autospec=True,
             return_value=self.fake_marathon_clients,
     ) as clients_patch, mock.patch(
             'paasta_tools.cleanup_marathon_jobs.delete_app',
             autospec=True,
     ) as delete_patch:
         cleanup_marathon_jobs.cleanup_apps(soa_dir)
         config_patch.assert_called_once_with()
         get_services_for_cluster_patch.assert_called_once_with(
             instance_type='marathon', soa_dir=soa_dir)
         clients_patch.assert_called_once_with(mock.ANY)
         delete_patch.assert_called_once_with(
             app_id='not-here.oh.no.weirdo',
             client=self.fake_marathon_client,
             soa_dir=soa_dir,
         )