Пример #1
0
    def setup(self):
        new_sample = {
            "counter_name": self.config["counter_name"],
            "counter_type": self.config["counter_type"],
            "counter_unit": self.config["counter_unit"],
            "counter_volume": self.config["counter_volume"],
        }
        resources = []

        for user, tenant_id in rutils.iterate_per_tenants(
                self.context["users"]):
            self.context["tenants"][tenant_id]["samples"] = []
            self.context["tenants"][tenant_id]["resources"] = []
            scenario = ceilo_utils.CeilometerScenario(
                context={
                    "user": user,
                    "task": self.context["task"]
                })
            for i in moves.xrange(self.config["resources_per_tenant"]):
                samples_to_create = scenario._make_samples(
                    count=self.config["samples_per_resource"],
                    interval=self.config["timestamp_interval"],
                    metadata_list=self.config.get("metadata_list"),
                    batch_size=self.config.get("batch_size"),
                    **new_sample)
                samples = self._store_batch_samples(
                    scenario, samples_to_create,
                    self.config.get("batches_allow_lose"))
                for sample in samples:
                    self.context["tenants"][tenant_id]["samples"].append(
                        sample.to_dict())
                self.context["tenants"][tenant_id]["resources"].append(
                    samples[0].resource_id)
                resources.append((user, samples[0].resource_id))

        # NOTE(boris-42): Context should wait until samples are processed
        from ceilometerclient import exc

        for user, resource_id in resources:
            scenario = ceilo_utils.CeilometerScenario(
                context={
                    "user": user,
                    "task": self.context["task"]
                })

            success = False
            for i in range(60):
                try:
                    scenario._get_resource(resource_id)
                    success = True
                    break
                except exc.HTTPNotFound:
                    time.sleep(3)
            if not success:
                raise exceptions.ContextSetupFailure(
                    ctx_name=self.get_name(),
                    msg="Ceilometer Resource %s is not found" % resource_id)
Пример #2
0
    def test_setup(self, mock_uuid, mock_create_samples, mock_get_resource):
        mock_uuid.uuid4.return_value = "fake_resource-id"
        tenants_count = 2
        users_per_tenant = 2
        resources_per_tenant = 2
        samples_per_resource = 2

        tenants, real_context = self._gen_context(tenants_count,
                                                  users_per_tenant,
                                                  resources_per_tenant,
                                                  samples_per_resource)
        scenario = ceilo_utils.CeilometerScenario(real_context)
        sample = {
            "counter_name":
            "fake-counter-name",
            "counter_type":
            "fake-counter-type",
            "counter_unit":
            "fake-counter-unit",
            "counter_volume":
            100,
            "metadata_list": [{
                "status": "active",
                "name": "fake_resource",
                "deleted": "False",
                "created_at": "2015-09-04T12:34:19.000000"
            }, {
                "status": "not_active",
                "name": "fake_resource_1",
                "deleted": "False",
                "created_at": "2015-09-10T06:55:12.000000"
            }]
        }
        kwargs = copy.deepcopy(sample)
        samples_to_create = list(
            scenario._make_samples(count=samples_per_resource,
                                   interval=60,
                                   **kwargs))[0]
        new_context = copy.deepcopy(real_context)
        for id_ in tenants.keys():
            new_context["tenants"][id_].setdefault("samples", [])
            new_context["tenants"][id_].setdefault("resources", [])
            for i in six.moves.xrange(resources_per_tenant):
                for sample in samples_to_create:
                    new_context["tenants"][id_]["samples"].append(sample)
                new_context["tenants"][id_]["resources"].append(
                    sample["resource_id"])

        mock_create_samples.return_value = []
        for i, sample in enumerate(samples_to_create):
            sample_object = mock.MagicMock(resource_id="fake_resource-id")
            sample_object.to_dict.return_value = sample
            mock_create_samples.return_value.append(sample_object)
        ceilometer_ctx = samples.CeilometerSampleGenerator(real_context)
        ceilometer_ctx.setup()
        self.assertEqual(new_context, ceilometer_ctx.context)
Пример #3
0
    def test__store_batch_samples(self):
        tenants_count = 2
        users_per_tenant = 2
        resources_per_tenant = 2
        samples_per_resource = 2

        tenants, real_context = self._gen_context(tenants_count,
                                                  users_per_tenant,
                                                  resources_per_tenant,
                                                  samples_per_resource)
        ceilometer_ctx = samples.CeilometerSampleGenerator(real_context)
        scenario = ceilo_utils.CeilometerScenario(real_context)
        self.assertRaises(exceptions.ContextSetupFailure,
                          ceilometer_ctx._store_batch_samples, scenario,
                          ["foo", "bar"], 1)
Пример #4
0
 def setUp(self):
     super(CeilometerScenarioTestCase, self).setUp()
     self.scenario = utils.CeilometerScenario(self.context)