Ejemplo n.º 1
0
 def test_verbose_one(self):
     args = ["--os-auth-url", "http://no.com", "-v", "server"]
     config = CloudCleanerConfig(args=args)
     ALL_RESOURCES["server"].register(config)
     config.parse_args()
     log = getLogger("cloud_cleaner")
     self.assertEqual(log.getEffectiveLevel(), INFO)
     conn = config.get_conn()
     self.assertIsInstance(conn, OpenStackCloud)
Ejemplo n.º 2
0
 def __test_with_calls(self, args, calls):
     conn = Mock()
     conn.list_floating_ips = Mock(return_value=FLOATING_IPS)
     conn.delete_floating_ip = Mock()
     calls = [call(i) for i in calls]
     config = CloudCleanerConfig(args=args)
     config.get_conn = Mock(return_value=conn)
     fip = Fip()
     fip.register(config)
     config.parse_args()
     fip.process()
     fip.clean()
     self.assertEqual(conn.delete_floating_ip.call_args_list, calls)
Ejemplo n.º 3
0
 def __test_with_call_order(self, args, calls):
     conn = Mock()
     conn.list_servers = Mock(return_value=SAMPLE_SERVERS)
     conn.delete_server = Mock()
     config = CloudCleanerConfig(args=args)
     config.get_conn = Mock(return_value=conn)
     calls = [call(c) for c in calls]
     server = Server(now=CURRENT_TIME)
     server.register(config)
     config.parse_args()
     server.prep_deletion()
     server.process()
     server.clean()
     self.assertEqual(conn.delete_server.call_args_list, calls)
Ejemplo n.º 4
0
 def test_email_with_calls(self):
     conn = Mock()
     conn.list_servers = Mock(return_value=SAMPLE_SERVERS)
     conn.get_user_by_id = Mock(return_value=SAMPLE_USER)
     conn.delete_server = Mock()
     config = CloudCleanerConfig(args=[
         "--os-auth-url", "http://no.com", "server", "--age", "4d",
         "--skip-name", "test-.*"
     ])
     config.get_conn = Mock(return_value=conn)
     calls = ['4', '5']
     calls = [call(c) for c in calls]
     server = Server(now=CURRENT_TIME)
     server.send_emails() = Mock()
     server.register(config)
     config.parse_args()
     server.process()
     server.send_emails()
     self.assertEqual(conn.get_user_by_id.call_count, 2)
     server.clean()
     self.assertEqual(conn.delete_server.call_args_list, calls)
Ejemplo n.º 5
0
 def test_email_with_delete(self):
     conn = Mock()
     conn.list_servers = Mock(return_value=SAMPLE_SERVERS)
     conn.get_user_by_id = Mock(return_value=SAMPLE_USER)
     conn.delete_server = Mock()
     config = CloudCleanerConfig(args=[
         "--os-auth-url", "http://no.com", "server", "--age", "4d",
         "--skip-name", "test-.*"
     ])
     config.get_conn = Mock(return_value=conn)
     server = Server(now=CURRENT_TIME)
     server.send_emails() = Mock()
     server.register(config)
     config.parse_args()
     server.prep_deletion()
     server.process()
     server.clean()
     server.process()
     server.send_emails()
     # Only server 4 should be deleted. As in the test above, servers 4 and
     # 5 fit the criteria, but this time around server 5 should be deleted,
     # and thus not considered for an email warning, whereas for server 4
     # nothing should change.
     self.assertEqual(conn.get_user_by_id.call_count, 1)