예제 #1
0
 def list_service_endpoints(self, organization_name, project_name):
     """List the different service endpoints in a project"""
     service_endpoint_manager = ServiceEndpointManager(
         organization_name=organization_name,
         project_name=project_name,
         creds=self._creds)
     return service_endpoint_manager.list_service_endpoints()
예제 #2
0
 def create_service_endpoint(self, organization_name, project_name, name):
     """Create a service endpoint to allow authentication via ARM service principal"""
     service_endpoint_manager = ServiceEndpointManager(
         organization_name=organization_name,
         project_name=project_name,
         creds=self._creds)
     return service_endpoint_manager.create_service_endpoint(name)
예제 #3
0
 def get_service_endpoints(self, organization_name, project_name, repository_name):
     """Query a service endpoint detail"""
     service_endpoint_manager = ServiceEndpointManager(
         organization_name=organization_name,
         project_name=project_name,
         creds=self._creds
     )
     return service_endpoint_manager.get_service_endpoints(repository_name)
예제 #4
0
 def setUp(self):
     self._build_definition_name = "_build_{org}_{proj}_{repo}".format(
         org=ORGANIZATION_NAME, proj=PROJECT_NAME, repo=REPOSITORY_NAME)
     self._release_definition_name = "_release_{org}_{proj}_{repo}".format(
         org=ORGANIZATION_NAME, proj=PROJECT_NAME, repo=REPOSITORY_NAME)
     self.release_manager = ReleaseManager(
         organization_name=ORGANIZATION_NAME,
         project_name=PROJECT_NAME,
         creds=get_credentials())
     self.service_endpoint_manager = ServiceEndpointManager(
         organization_name=ORGANIZATION_NAME, project_name=PROJECT_NAME)
class TestServiceEndpointManager(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        logging.disable(logging.CRITICAL)

    @classmethod
    def tearDownClass(cls):
        logging.disable(logging.NOTSET)

    def setUp(self):
        self.service_endpoint_manager = ServiceEndpointManager(
            organization_name=ORGANIZATION_NAME,
            project_name=PROJECT_NAME,
            creds=get_credentials())

    @unittest.SkipTest
    def test_get_service_endpoints(self):
        endpoints = self.service_endpoint_manager.get_service_endpoints(
            REPOSITORY_NAME)
        self.assertIsNotNone(endpoints)
        self.assertGreaterEqual(len(endpoints), 0)

    @unittest.SkipTest
    def test_get_service_endpoints_has_existing_endpoint(self):
        expected_endpoint_name = self.service_endpoint_manager._get_service_endpoint_name(
            REPOSITORY_NAME, "pipeline")
        endpoints = self.service_endpoint_manager.get_service_endpoints(
            REPOSITORY_NAME)
        if len(endpoints) > 0:
            self.assertEqual(endpoints[0].name, expected_endpoint_name)

    @unittest.skipIf(
        not CREATE_DEVOPS_OBJECTS,
        "Set CREATE_DEVOPS_OBJECTS to True if you want to create resources for testing"
    )
    def test_create_service_endpoint(self):
        expected_endpoint_name = self.service_endpoint_manager._get_service_endpoint_name(
            REPOSITORY_NAME, "pipeline")
        existing_endpoints = self.service_endpoint_manager.get_service_endpoints(
            REPOSITORY_NAME)

        # Skip if endpoint exists
        if len(existing_endpoints) > 0:
            raise unittest.SkipTest("Service endpoint does not exist")

        # Skip if role assignment permission is not granted
        try:
            endpoint = self.service_endpoint_manager.create_service_endpoint(
                expected_endpoint_name)
        except RoleAssignmentException:
            raise unittest.SkipTest(
                "Test operator may not have RoleAssignment/Write permission")

        self.assertIsNotNone(endpoint)
        self.assertEqual(endpoint.name, expected_endpoint_name)
 def list_service_endpoints(self, organization_name, project_name):
     """List the different service endpoints in a project"""
     service_endpoint_manager = ServiceEndpointManager(organization_name=organization_name,
                                                       project_name=project_name, creds=self._creds)
     return service_endpoint_manager.list_service_endpoints()
 def create_service_endpoint(self, organization_name, project_name, name):
     """Create a service endpoint to allow authentication via ARM service principal"""
     service_endpoint_manager = ServiceEndpointManager(organization_name=organization_name,
                                                       project_name=project_name, creds=self._creds)
     return service_endpoint_manager.create_service_endpoint(name)
 def setUp(self):
     self.service_endpoint_manager = ServiceEndpointManager(
         organization_name=ORGANIZATION_NAME,
         project_name=PROJECT_NAME,
         creds=get_credentials())
예제 #9
0
class TestReleaseManager(unittest.TestCase):
    def setUp(self):
        self._build_definition_name = "_build_{org}_{proj}_{repo}".format(
            org=ORGANIZATION_NAME, proj=PROJECT_NAME, repo=REPOSITORY_NAME)
        self._release_definition_name = "_release_{org}_{proj}_{repo}".format(
            org=ORGANIZATION_NAME, proj=PROJECT_NAME, repo=REPOSITORY_NAME)
        self.release_manager = ReleaseManager(
            organization_name=ORGANIZATION_NAME,
            project_name=PROJECT_NAME,
            creds=get_credentials())
        self.service_endpoint_manager = ServiceEndpointManager(
            organization_name=ORGANIZATION_NAME, project_name=PROJECT_NAME)

    def test_list_release_definitions(self):
        definitions = self.release_manager.list_release_definitions()
        self.assertIsNotNone(definitions)
        self.assertGreaterEqual(len(definitions), 0)

    def test_list_releases(self):
        releases = self.release_manager.list_releases()
        self.assertIsNotNone(releases)
        self.assertGreaterEqual(len(releases), 0)

    @unittest.skipIf(
        not CREATE_DEVOPS_OBJECTS,
        "Set CREATE_DEVOPS_OBJECTS to True if you want to create resources for unit testing"
    )
    def test_create_release_definition(self):
        service_endpoint_name = self.service_endpoint_manager._get_service_endpoint_name(
            REPOSITORY_NAME, "pipeline")

        # Skip if service endpoint does not exist
        if service_endpoint_name is None:
            raise unittest.SkipTest(
                "There is no service endpoint. Cannot create release definition."
            )

        # Skip if release definition already exists
        definitions = self.release_manager.list_release_definitions()
        if self._release_definition_name in [d.name for d in definitions]:
            raise unittest.SkipTest(
                "The release definition exists. No need to create one.")

        new_definition = self.release_manager.create_release_definition(
            build_name=self._build_definition_name,
            artifact_name='drop',
            pool_name="Hosted VS2017",
            service_endpoint_name=service_endpoint_name,
            release_definition_name=self._release_definition_name,
            app_type=FUNCTIONAPP_TYPE,
            functionapp_name=FUNCTIONAPP_NAME,
            storage_name=STORAGE_NAME,
            resource_name=RESOURCE_GROUP_NAME)
        self.assertIsNotNone(new_definition)
        self.assertEqual(new_definition.name, self._release_definition_name)

    @unittest.skipIf(
        not CREATE_DEVOPS_OBJECTS,
        "Set CREATE_DEVOPS_OBJECTS to True if you want to create resources for unit testing"
    )
    def test_create_release(self):
        # Skip if release definition does not exist
        definitions = self.release_manager.list_release_definitions()
        if not self._release_definition_name in [d.name for d in definitions]:
            raise unittest.SkipTest(
                "There is no release definition. Cannot create a new release.")

        release = self.release_manager.create_release(
            self._release_definition_name)
        self.assertIsNotNone(release)