Example #1
0
    def test_get_accounts_from_source(self):
        """Test to get all accounts"""
        accounts = CURAccountsDB().get_accounts_from_source()
        if len(accounts) != 1:
            self.fail('unexpected number of accounts')

        account = accounts.pop()

        self.assertEqual(account.get('authentication'),
                         'arn:aws:iam::111111111111:role/CostManagement')
        self.assertEqual(account.get('billing_source'), 'test-bucket')
        self.assertEqual(account.get('customer_name'), 'Test Customer')
        self.assertEqual(account.get('provider_type'), AMAZON_WEB_SERVICES)
Example #2
0
    def test_get_specific_account_with_active_and_paused(self):
        """Test to get accounts when either active or paused."""
        first = Provider.objects.first()

        table = [
            {
                "active": True,
                "paused": True,
                "expected": 0
            },
            {
                "active": True,
                "paused": False,
                "expected": 1
            },
            {
                "active": False,
                "paused": True,
                "expected": 0
            },
            {
                "active": False,
                "paused": False,
                "expected": 0
            },
        ]
        for test in table:
            first.active = test["active"]
            first.paused = test["paused"]
            first.save()
            accounts = CURAccountsDB().get_accounts_from_source(first.uuid)
            self.assertEqual(len(accounts), test["expected"])
Example #3
0
    def test_get_accounts_with_active_and_paused(self):
        """Test to get accounts when either active or paused."""
        providers = Provider.objects.all()
        num_providers = len(providers)
        first = providers[0]

        table = [
            {
                "active": True,
                "paused": True,
                "expected": num_providers - 1
            },
            {
                "active": True,
                "paused": False,
                "expected": num_providers
            },
            {
                "active": False,
                "paused": True,
                "expected": num_providers - 1
            },
            {
                "active": False,
                "paused": False,
                "expected": num_providers - 1
            },
        ]
        for test in table:
            first.active = test["active"]
            first.paused = test["paused"]
            first.save()
            accounts = CURAccountsDB().get_accounts_from_source()
            self.assertEqual(len(accounts), test["expected"])
Example #4
0
    def test_get_accounts_from_source(self):
        """Test to get all accounts."""
        accounts = CURAccountsDB().get_accounts_from_source()
        if len(accounts) != 3:
            self.fail('unexpected number of accounts')

        for account in accounts:
            if account.get('provider_type') == Provider.PROVIDER_AWS:
                self.assertEqual(account.get('authentication'),
                                 self.aws_provider_resource_name)
                self.assertEqual(account.get('billing_source'),
                                 self.aws_test_billing_source)
                self.assertEqual(account.get('customer_name'), self.schema)
            elif account.get('provider_type') == Provider.PROVIDER_OCP:
                self.assertEqual(account.get('authentication'),
                                 self.ocp_provider_resource_name)
                self.assertEqual(account.get('billing_source'), None)
                self.assertEqual(account.get('customer_name'), self.schema)
            elif account.get('provider_type') == Provider.PROVIDER_AZURE:
                self.assertEqual(account.get('authentication'),
                                 self.azure_credentials)
                self.assertEqual(account.get('billing_source'),
                                 self.azure_data_source)
                self.assertEqual(account.get('customer_name'), self.schema)
            else:
                self.fail('Unexpected provider')
Example #5
0
    def test_get_accounts_from_source(self):
        """Test to get all accounts"""
        accounts = CURAccountsDB().get_accounts_from_source()
        if len(accounts) != 3:
            self.fail('unexpected number of accounts')

        for account in accounts:
            if account.get('provider_type') == AMAZON_WEB_SERVICES:
                self.assertEqual(account.get('authentication'),
                                 self.aws_provider_resource_name)
                self.assertEqual(account.get('billing_source'),
                                 self.aws_test_billing_source)
                self.assertEqual(account.get('customer_name'), self.schema)
            elif account.get('provider_type') == OPENSHIFT_CONTAINER_PLATFORM:
                self.assertEqual(account.get('authentication'),
                                 self.ocp_provider_resource_name)
                self.assertEqual(account.get('billing_source'), None)
                self.assertEqual(account.get('customer_name'), self.schema)
            elif account.get('provider_type') == AZURE:
                self.assertEqual(account.get('authentication'),
                                 self.azure_credentials)
                self.assertEqual(account.get('billing_source'),
                                 self.azure_data_source)
                self.assertEqual(account.get('customer_name'), self.schema)
            else:
                self.fail('Unexpected provider')
Example #6
0
    def test_get_accounts_from_source_with_inactive(self):
        """Test to get all active accounts."""
        self.aws_provider.active = False
        self.aws_provider.save()

        accounts = CURAccountsDB().get_accounts_from_source()
        if len(accounts) != 2:
            self.fail("unexpected number of accounts")
Example #7
0
    def test_get_accounts_from_source_with_inactive(self):
        """Test to get all active accounts."""
        self.aws_provider.active = False
        self.aws_provider.save()
        expected_count = Provider.objects.filter(active=True).count()

        accounts = CURAccountsDB().get_accounts_from_source()
        if len(accounts) != expected_count:
            self.fail("unexpected number of accounts")
Example #8
0
    def test_get_accounts_from_source(self):
        """Test to get all accounts."""
        accounts = CURAccountsDB().get_accounts_from_source()
        expected_count = Provider.objects.count()
        self.assertEqual(len(accounts), expected_count)

        for account in accounts:
            if account.get("provider_type") in (Provider.PROVIDER_AWS,
                                                Provider.PROVIDER_AWS_LOCAL):
                self.assertEqual(account.get("credentials"),
                                 self.aws_provider.authentication.credentials)
                self.assertEqual(account.get("data_source"),
                                 self.aws_provider.billing_source.data_source)
                self.assertEqual(account.get("customer_name"), self.schema)
            elif account.get("provider_type") == Provider.PROVIDER_OCP:
                self.assertIn(
                    account.get("credentials"),
                    [
                        self.ocp_provider.authentication.
                        credentials,  # OCP-on-Prem
                        self.ocp_on_aws_ocp_provider.authentication.
                        credentials,
                        self.ocp_on_azure_ocp_provider.authentication.
                        credentials,
                        self.ocp_on_gcp_ocp_provider.authentication.
                        credentials,
                    ],
                )
                self.assertTrue(
                    (account.get("data_source")
                     == self.ocp_provider.billing_source.data_source)
                    or account.get("data_source") is None)
                self.assertEqual(account.get("customer_name"), self.schema)
            elif account.get("provider_type") in (
                    Provider.PROVIDER_AZURE, Provider.PROVIDER_AZURE_LOCAL):
                self.assertEqual(
                    account.get("credentials"),
                    self.azure_provider.authentication.credentials)
                self.assertEqual(
                    account.get("data_source"),
                    self.azure_provider.billing_source.data_source)
                self.assertEqual(account.get("customer_name"), self.schema)
            elif account.get("provider_type") in (Provider.PROVIDER_GCP,
                                                  Provider.PROVIDER_GCP_LOCAL):
                self.assertEqual(account.get("credentials"),
                                 self.gcp_provider.authentication.credentials)
                self.assertEqual(account.get("data_source"),
                                 self.gcp_provider.billing_source.data_source)
                self.assertEqual(account.get("customer_name"), self.schema)
            else:
                self.fail("Unexpected provider")
Example #9
0
    def _set_source(self):
        """
        Create the provider service object.

        Set what source should be used to get CUR accounts.

        Args:
            None

        Returns:
            (Object) : Some object that is a child of CURAccountsInterface

        """
        if self.source_type == "db":
            return CURAccountsDB()

        return None
Example #10
0
    def test_handle_missing_foreign_data(self):
        p = Provider.objects.first()
        p.customer = None
        p.billing_source = None
        p.authentication = None
        exc = None

        try:
            info = CURAccountsDB.get_account_information(p)
        except Exception as e:
            exc = e

        self.assertIsNone(exc)
        self.assertIsNone(info["customer_name"])
        self.assertIsNone(info["credentials"])
        self.assertIsNone(info["data_source"])
        self.assertIsNone(info["schema_name"])
Example #11
0
    def test_get_accounts_from_source(self):
        """Test to get all accounts"""
        accounts = CURAccountsDB().get_accounts_from_source()
        if len(accounts) != 2:
            self.fail('unexpected number of accounts')

        for account in accounts:
            if account.get('provider_type') == AMAZON_WEB_SERVICES:
                self.assertEqual(
                    account.get('authentication'),
                    'arn:aws:iam::111111111111:role/CostManagement',
                )
                self.assertEqual(account.get('billing_source'), 'test-bucket')
                self.assertEqual(account.get('customer_name'), 'acct10001')
            elif account.get('provider_type') == OPENSHIFT_CONTAINER_PLATFORM:
                self.assertEqual(account.get('authentication'),
                                 'my-ocp-cluster-1')
                self.assertEqual(account.get('billing_source'), None)
                self.assertEqual(account.get('customer_name'), 'acct10001')
            else:
                self.fail('Unexpected provider')