def check_sub_id(self, subscription_id): azure_key = AzureKey.objects(subscription_id=subscription_id).first() if self.util.is_local(): if azure_key is not None: azure_key.verified = True azure_key.save() return ok("success") if azure_key is None: return internal_server_error( "No available azure key on the server side.") sms = CloudServiceAdapter(azure_key.subscription_id, azure_key.get_local_pem_url(), host=azure_key.management_host) if sms.ping(): azure_key.verified = True azure_key.save() else: return bad_request( "Subscription id is not valid, check whether subscription id is valid and upload the right cer file to azure" ) return ok("success")
def check_sub_id(self, subscription_id): azure_key = AzureKey.objects(subscription_id=subscription_id).first() if self.util.is_local(): if azure_key is not None: azure_key.verified = True azure_key.save() return ok(True) if azure_key is None: return ok(False) try: sms = CloudServiceAdapter(azure_key.subscription_id, azure_key.get_local_pem_url(), host=azure_key.management_host) sms.list_hosted_services() azure_key.verified = True azure_key.save() except Exception as e: return ok(False) return ok(True)
def is_host_server_locked(self, docker_host): # todo which azure key to use? azure_key = docker_host.hackathon.azure_keys[0] cloudservice = CloudServiceAdapter(azure_key.subscription_id, azure_key.get_local_pem_url(), host=azure_key.management_host) service_name = docker_host.public_dns.split(".")[0] return cloudservice.is_cloud_service_locked(service_name)
def report_health(self): azure_key = AzureKey.objects().first() if not azure_key: return { STATUS: HEALTH_STATUS.WARNING, DESCRIPTION: "No Azure key found" } service = CloudServiceAdapter(azure_key.id) if service.ping(): return {STATUS: HEALTH_STATUS.OK, "type": "Azure Storage"} else: return {STATUS: HEALTH_STATUS.ERROR}
def report_health(self): azure_key = AzureKey.objects().first() if not azure_key: return { STATUS: HEALTH_STATUS.WARNING, DESCRIPTION: "No Azure key found" } service = CloudServiceAdapter(azure_key.id) if service.ping(): return { STATUS: HEALTH_STATUS.OK, "type": "Azure Storage" } else: return { STATUS: HEALTH_STATUS.ERROR }
def check_sub_id(self, subscription_id): azure_key = AzureKey.objects(subscription_id=subscription_id).first() if self.util.is_local(): if azure_key is not None: azure_key.verified = True azure_key.save() return ok("success") if azure_key is None: return internal_server_error("No available azure key on the server side.") sms = CloudServiceAdapter(azure_key.subscription_id, azure_key.get_local_pem_url(), host=azure_key.management_host) if sms.ping(): azure_key.verified = True azure_key.save() else: return bad_request("Subscription id is not valid, check whether subscription id is valid and upload the right cer file to azure") return ok("success")
def setUp(self): self.service = CloudServiceAdapter(test_conf.subscription_id, test_conf.pem_url, host=test_conf.management_host)
class CloudServiceAdapterTest(unittest.TestCase): def setUp(self): self.service = CloudServiceAdapter(test_conf.subscription_id, test_conf.pem_url, host=test_conf.management_host) def tearDown(self): pass @unittest.skip("heavy test require real connection to azure cloud") def test_cloud_service_exisits_real(self): self.assertTrue( self.service.cloud_service_exists( test_conf.azure_cloud_service_name_should_exist)) self.assertFalse( self.service.cloud_service_exists(test_conf.meanless_name)) @unittest.skip("test_cloud_service") def test_cloud_service(self): mock = Mock() self.service.service.get_hosted_service_properties = mock mock.return_value = True self.assertTrue( self.service.cloud_service_exists(test_conf.meanless_name)) mock.return_value = None self.assertFalse( self.service.cloud_service_exists(test_conf.meanless_name)) mock.side_effect = AzureMissingResourceHttpError(233, 233) self.assertFalse( self.service.cloud_service_exists(test_conf.meanless_name)) @unittest.skip("heavy test require real connection to azure cloud") def test_create_cloud_service_real(self): print "After run this test, don't forget to delete resources on azure cloud" self.assertTrue( self.service.create_cloud_service( test_conf.azure_cloud_service_to_create["name"], test_conf.azure_cloud_service_to_create["label"], test_conf.azure_cloud_service_to_create["location"])) self.assertTrue( self.service.cloud_service_exists( test_conf.azure_cloud_service_to_create["name"])) self.assertFalse( self.service.create_cloud_service( test_conf.azure_cloud_service_to_create["name"], test_conf.azure_cloud_service_to_create["label"], test_conf.azure_cloud_service_to_create["location"])) @unittest.skip("test_creat_hosted_servic") def test_creat_hosted_service(self): mock_create = Mock() mock_wait = Mock() self.service.service.create_cloud_service = mock_create self.service.service.wait_for_operation_status = mock_wait mock_create.return_value = Context(request_id=test_conf.meanless_id) mock_wait.return_value = Context(status=ASYNC_OP_RESULT.SUCCEEDED) self.assertTrue( self.service.create_cloud_service(test_conf.meanless_name, test_conf.meanless_name, test_conf.meanless_name)) mock_create.side_effect = AzureHttpError(233, 233) self.assertFalse( self.service.create_cloud_service(test_conf.meanless_name, test_conf.meanless_name, test_conf.meanless_name)) @unittest.skip("test_create_cloud_servic") def test_create_cloud_service(self): mock_exist = Mock() mock_create = Mock() mock_db = Mock() self.service.cloud_service_exists = mock_exist self.service.create_cloud_service = mock_create self.service.db = mock_db mock_exist.return_value = False mock_create.return_value = False self.assertFalse( self.service.create_cloud_service(test_conf.meanless_id, test_conf.meanless_name, test_conf.meanless_name, test_conf.meanless_name)) # TODO: ignored db check mock_exist.return_value = True mock_create.return_value = True self.assertTrue( self.service.create_cloud_service(test_conf.meanless_id, test_conf.meanless_name, test_conf.meanless_name, test_conf.meanless_name))
def setUp(self): self.service = CloudServiceAdapter( test_conf.subscription_id, test_conf.pem_url, host=test_conf.management_host)
class CloudServiceAdapterTest(unittest.TestCase): def setUp(self): self.service = CloudServiceAdapter( test_conf.subscription_id, test_conf.pem_url, host=test_conf.management_host) def tearDown(self): pass @unittest.skip("heavy test require real connection to azure cloud") def test_cloud_service_exisits_real(self): self.assertTrue(self.service.cloud_service_exists( test_conf.azure_cloud_service_name_should_exist)) self.assertFalse(self.service.cloud_service_exists( test_conf.meanless_name)) def test_cloud_service(self): mock = Mock() self.service.service.get_hosted_service_properties = mock mock.return_value = True self.assertTrue(self.service.cloud_service_exists( test_conf.meanless_name)) mock.return_value = None self.assertFalse(self.service.cloud_service_exists( test_conf.meanless_name)) mock.side_effect = AzureMissingResourceHttpError(233, 233) self.assertFalse(self.service.cloud_service_exists( test_conf.meanless_name)) @unittest.skip("heavy test require real connection to azure cloud") def test_create_cloud_service_real(self): print "After run this test, don't forget to delete resources on azure cloud" self.assertTrue(self.service.create_cloud_service( test_conf.azure_cloud_service_to_create["name"], test_conf.azure_cloud_service_to_create["label"], test_conf.azure_cloud_service_to_create["location"])) self.assertTrue(self.service.cloud_service_exists( test_conf.azure_cloud_service_to_create["name"])) self.assertFalse(self.service.create_cloud_service( test_conf.azure_cloud_service_to_create["name"], test_conf.azure_cloud_service_to_create["label"], test_conf.azure_cloud_service_to_create["location"])) def test_creat_hosted_service(self): mock_create = Mock() mock_wait = Mock() self.service.service.create_cloud_service = mock_create self.service.service.wait_for_operation_status = mock_wait mock_create.return_value = Context(request_id=test_conf.meanless_id) mock_wait.return_value = Context(status=ASYNC_OP_RESULT.SUCCEEDED) self.assertTrue(self.service.create_cloud_service( test_conf.meanless_name, test_conf.meanless_name, test_conf.meanless_name)) mock_create.side_effect = AzureHttpError(233, 233) self.assertFalse(self.service.create_cloud_service( test_conf.meanless_name, test_conf.meanless_name, test_conf.meanless_name)) def test_create_cloud_service(self): mock_exist = Mock() mock_create = Mock() mock_db = Mock() self.service.cloud_service_exists = mock_exist self.service.create_cloud_service = mock_create self.service.db = mock_db mock_exist.return_value = False mock_create.return_value = False self.assertFalse(self.service.create_cloud_service( test_conf.meanless_id, test_conf.meanless_name, test_conf.meanless_name, test_conf.meanless_name)) # TODO: ignored db check mock_exist.return_value = True mock_create.return_value = True self.assertTrue(self.service.create_cloud_service( test_conf.meanless_id, test_conf.meanless_name, test_conf.meanless_name, test_conf.meanless_name))