Beispiel #1
0
 def test_get_schema(self):
     """Test provider schema getter."""
     uuid = self.aws_test_provider_uuid
     expected_schema = self.test_schema
     accessor = ProviderDBAccessor(uuid)
     self.assertEqual(expected_schema, accessor.get_schema())
     accessor.close_session()
Beispiel #2
0
 def test_get_customer_name(self):
     """Test provider customer getter."""
     uuid = self.aws_test_provider_uuid
     expected_customer_name = self.test_schema
     accessor = ProviderDBAccessor(uuid)
     self.assertEqual(expected_customer_name, accessor.get_customer_name())
     accessor.close_session()
Beispiel #3
0
 def test_get_authentication(self):
     """Test provider authentication getter."""
     uuid = self.aws_test_provider_uuid
     expected_auth_string = self.aws_provider_resource_name
     accessor = ProviderDBAccessor(uuid)
     self.assertEqual(expected_auth_string, accessor.get_authentication())
     accessor.close_session()
Beispiel #4
0
 def setUp(self):
     """Test set up."""
     super().setUp()
     provider_accessor = ProviderDBAccessor(self.aws_provider_uuid)
     provider = provider_accessor.get_provider()
     self.provider_uuid = provider.uuid
     provider_accessor.close_session()
Beispiel #5
0
 def test_initializer_auth_id(self):
     """Test Initializer with authentication database id."""
     auth_id = self.aws_db_auth_id
     accessor = ProviderDBAccessor(auth_id=auth_id)
     self.assertIsNotNone(accessor._session)
     self.assertTrue(accessor.does_db_entry_exist())
     accessor.close_session()
Beispiel #6
0
 def test_initializer_provider_uuid(self):
     """Test Initializer with provider uuid."""
     uuid = self.aws_test_provider_uuid
     accessor = ProviderDBAccessor(uuid)
     self.assertIsNotNone(accessor._session)
     self.assertTrue(accessor.does_db_entry_exist())
     accessor.close_session()
 def test_initializer(self):
     """Test Initializer"""
     uuid = '6e212746-484a-40cd-bba0-09a19d132d64'
     accessor = ProviderDBAccessor(uuid)
     self.assertIsNotNone(accessor._session)
     self.assertTrue(accessor.does_db_entry_exist())
     accessor.close_session()
Beispiel #8
0
    def get_accounts_from_source(self):
        """
        Retrieve all accounts from the Koku database.

        This will return a list of dicts for the Orchestrator to use to access reports.

        Args:
            None

        Returns:
            ([{}]) : A list of dicts

        """
        collector = ProviderCollector()
        all_providers = collector.get_providers()
        collector.close_session()

        accounts = []
        for provider in all_providers:
            provider_accessor = ProviderDBAccessor(provider.uuid)
            accounts.append({
                'authentication':
                provider_accessor.get_authentication(),
                'billing_source':
                provider_accessor.get_billing_source(),
                'customer_name':
                provider_accessor.get_customer_name(),
                'provider_type':
                provider_accessor.get_type(),
                'schema_name':
                provider_accessor.get_schema()
            })
            provider_accessor.close_session()
        return accounts
 def test_get_schema(self):
     """Test provider schema getter."""
     uuid = '6e212746-484a-40cd-bba0-09a19d132d64'
     expected_schema = 'testcustomer'
     accessor = ProviderDBAccessor(uuid)
     self.assertEqual(expected_schema, accessor.get_schema())
     accessor.close_session()
 def test_get_authentication(self):
     """Test provider authentication getter."""
     uuid = '6e212746-484a-40cd-bba0-09a19d132d64'
     expected_auth_string = 'arn:aws:iam::111111111111:role/CostManagement'
     accessor = ProviderDBAccessor(uuid)
     self.assertEqual(expected_auth_string, accessor.get_authentication())
     accessor.close_session()
 def test_get_customer_name(self):
     """Test provider customer getter."""
     uuid = '6e212746-484a-40cd-bba0-09a19d132d64'
     expected_customer_name = 'Test Customer'
     accessor = ProviderDBAccessor(uuid)
     self.assertEqual(expected_customer_name, accessor.get_customer_name())
     accessor.close_session()
 def test_get_billing_source(self):
     """Test provider billing_source getter."""
     uuid = '6e212746-484a-40cd-bba0-09a19d132d64'
     expected_billing_source = 'test-bucket'
     accessor = ProviderDBAccessor(uuid)
     self.assertEqual(expected_billing_source,
                      accessor.get_billing_source())
     accessor.close_session()
Beispiel #13
0
 def test_initializer_provider_uuid_and_auth_id_mismatch(self):
     """Test Initializer with provider uuid and authentication database id mismatch."""
     auth_id = self.ocp_db_auth_id
     uuid = self.aws_test_provider_uuid
     accessor = ProviderDBAccessor(provider_uuid=uuid, auth_id=auth_id)
     self.assertIsNotNone(accessor._session)
     self.assertFalse(accessor.does_db_entry_exist())
     accessor.close_session()
Beispiel #14
0
 def test_get_billing_source(self):
     """Test provider billing_source getter."""
     uuid = self.aws_test_provider_uuid
     expected_billing_source = 'test-bucket'
     accessor = ProviderDBAccessor(uuid)
     self.assertEqual(expected_billing_source,
                      accessor.get_billing_source())
     accessor.close_session()
 def test_get_customer_uuid(self):
     """Test provider billing_source getter."""
     uuid = '6e212746-484a-40cd-bba0-09a19d132d64'
     accessor = ProviderDBAccessor(uuid)
     customer = CustomerDBAccessor(1)
     expected_uuid = customer.get_uuid()
     self.assertEqual(expected_uuid, accessor.get_customer_uuid())
     accessor.close_session()
     customer.close_session()
Beispiel #16
0
    def test_setup_complete(self):
        """Test provider setup_complete method."""
        uuid = self.aws_test_provider_uuid
        accessor = ProviderDBAccessor(uuid)
        accessor.setup_complete()
        accessor.commit()
        self.assertEqual(True, accessor.get_setup_complete())

        accessor.close_session()
Beispiel #17
0
 def test_get_customer_uuid(self):
     """Test provider billing_source getter."""
     uuid = self.aws_test_provider_uuid
     accessor = ProviderDBAccessor(uuid)
     customer = CustomerDBAccessor(1)
     expected_uuid = customer.get_uuid()
     self.assertEqual(expected_uuid, accessor.get_customer_uuid())
     accessor.close_session()
     customer.close_session()
 def test_get_type(self):
     """Test provider type getter."""
     uuid = '6e212746-484a-40cd-bba0-09a19d132d64'
     accessor = ProviderDBAccessor(uuid)
     self.assertEqual(AMAZON_WEB_SERVICES, accessor.get_type())
     accessor.close_session()
Beispiel #19
0
 def test_initializer_no_args(self):
     """Test Initializer with no arguments."""
     accessor = ProviderDBAccessor()
     self.assertIsNotNone(accessor._session)
     self.assertTrue(accessor.does_db_entry_exist())
     accessor.close_session()
 def test_get_uuid(self):
     """Test uuid getter."""
     uuid = '6e212746-484a-40cd-bba0-09a19d132d64'
     accessor = ProviderDBAccessor(uuid)
     self.assertEqual(uuid, accessor.get_uuid())
     accessor.close_session()
Beispiel #21
0
 def test_get_type(self):
     """Test provider type getter."""
     uuid = self.aws_test_provider_uuid
     accessor = ProviderDBAccessor(uuid)
     self.assertEqual(AMAZON_WEB_SERVICES, accessor.get_type())
     accessor.close_session()
Beispiel #22
0
 def test_get_provider_name(self):
     """Test provider name getter."""
     uuid = self.aws_test_provider_uuid
     accessor = ProviderDBAccessor(uuid)
     self.assertEqual('Test Provider', accessor.get_provider_name())
     accessor.close_session()
Beispiel #23
0
 def test_get_uuid(self):
     """Test uuid getter."""
     uuid = self.aws_test_provider_uuid
     accessor = ProviderDBAccessor(uuid)
     self.assertEqual(uuid, accessor.get_uuid())
     accessor.close_session()
Beispiel #24
0
class OCPUtilTests(MasuTestCase):
    """Test the OCP utility functions."""
    def setUp(self):
        super().setUp()
        self.common_accessor = ReportingCommonDBAccessor()
        self.column_map = self.common_accessor.column_map
        self.accessor = OCPReportDBAccessor(schema=self.test_schema,
                                            column_map=self.column_map)
        self.provider_accessor = ProviderDBAccessor(
            provider_uuid=self.ocp_test_provider_uuid)
        self.report_schema = self.accessor.report_schema
        self.creator = ReportObjectCreator(self.accessor, self.column_map,
                                           self.report_schema.column_types)
        self.all_tables = list(OCP_REPORT_TABLE_MAP.values())

        self.provider_id = self.provider_accessor.get_provider().id
        reporting_period = self.creator.create_ocp_report_period(
            provider_id=self.provider_id)
        report = self.creator.create_ocp_report(
            reporting_period, reporting_period.report_period_start)
        self.creator.create_ocp_usage_line_item(reporting_period, report)
        self.creator.create_ocp_storage_line_item(reporting_period, report)

    def tearDown(self):
        """Return the database to a pre-test state."""
        self.accessor._session.rollback()
        for table_name in self.all_tables:
            tables = self.accessor._get_db_obj_query(table_name).all()
            for table in tables:
                self.accessor._session.delete(table)
        self.accessor.commit()
        self.accessor.close_session()
        self.provider_accessor.close_session()
        self.common_accessor.close_session()

    def test_get_cluster_id_from_provider(self):
        """Test that the cluster ID is returned from OCP provider."""
        cluster_id = utils.get_cluster_id_from_provider(
            self.ocp_test_provider_uuid)
        self.assertIsNotNone(cluster_id)

    def test_get_cluster_id_from_non_ocp_provider(self):
        """Test that None is returned when getting cluster ID on non-OCP provider."""
        cluster_id = utils.get_cluster_id_from_provider(
            self.aws_test_provider_uuid)
        self.assertIsNone(cluster_id)

    def test_get_provider_uuid_from_cluster_id(self):
        """Test that the provider uuid is returned for a cluster ID."""
        cluster_id = self.ocp_provider_resource_name
        provider_uuid = utils.get_provider_uuid_from_cluster_id(cluster_id)
        try:
            UUID(provider_uuid)
        except ValueError:
            self.fail('{} is not a valid uuid.'.format(str(provider_uuid)))

    def test_get_provider_uuid_from_invalid_cluster_id(self):
        """Test that the provider uuid is not returned for an invalid cluster ID."""
        cluster_id = 'bad_cluster_id'
        provider_uuid = utils.get_provider_uuid_from_cluster_id(cluster_id)
        self.assertIsNone(provider_uuid)

    def test_poll_ingest_override_for_provider(self):
        """Test that OCP polling override returns True if insights local path exists."""
        fake_dir = tempfile.mkdtemp()
        with patch.object(Config, 'INSIGHTS_LOCAL_REPORT_DIR', fake_dir):
            cluster_id = utils.get_cluster_id_from_provider(
                self.ocp_test_provider_uuid)
            expected_path = '{}/{}/'.format(Config.INSIGHTS_LOCAL_REPORT_DIR,
                                            cluster_id)
            os.makedirs(expected_path, exist_ok=True)
            self.assertTrue(
                utils.poll_ingest_override_for_provider(
                    self.ocp_test_provider_uuid))
        shutil.rmtree(fake_dir)
Beispiel #25
0
 def test_get_setup_complete(self):
     """Test provider setup_complete getter."""
     uuid = self.aws_test_provider_uuid
     accessor = ProviderDBAccessor(uuid)
     self.assertEqual(False, accessor.get_setup_complete())
     accessor.close_session()
 def test_get_provider_name(self):
     """Test provider name getter."""
     uuid = '6e212746-484a-40cd-bba0-09a19d132d64'
     accessor = ProviderDBAccessor(uuid)
     self.assertEqual('Test Provider', accessor.get_provider_name())
     accessor.close_session()