Exemplo n.º 1
0
    def test_fipset_get_unit_price_with_again_event(self):
        rate_limit = 10240
        quantity = pricing.rate_limit_to_unit(rate_limit)
        expected_price = pricing.calculate_price(
            quantity, self.product.unit_price)

        payload = self.build_floatingipset_payload(
            self.fipset, rate_limit, self.admin_account.project_id)
        payload = payload['floatingipset']
        fipset = neutron.FloatingIpSet(
            id=payload['id'], name=payload['uos:name'],
            size=payload['rate_limit'], project_id=payload['tenant_id'],
            providers=payload['uos:service_provider'],
            resource_type=gring_const.RESOURCE_FLOATINGIPSET,
            status=payload['status'], is_reserved=True)
        message = fipset.to_message()

        handle = floatingip.FloatingIpCreateEnd()
        handle.process_notification(message)

        resource_id = payload['id']
        order = self.dbconn.get_order_by_resource_id(
            self.admin_req_context, resource_id)

        price = handle.get_unit_price(order.order_id,
                                      message,
                                      gring_const.STATE_RUNNING)
        self.assertDecimalEqual(expected_price, price)
Exemplo n.º 2
0
    def test_floatingip_change_unit_price(self):
        product = self.product_fixture.ip_products[0]
        project_id = self.admin_account.project_id
        end_time = self.utcnow()
        start_time = end_time - datetime.timedelta(hours=1)

        # rate_limit = 1024
        rate_limit = 1024
        resource_id = self.create_floatingip(
            rate_limit, project_id, timestamp=start_time)
        order = self.dbconn.get_order_by_resource_id(
            self.admin_req_context, resource_id)

        # change rate_limit to 1024 * 11
        rate_limit = 1024 * 11
        quantity = pricing.rate_limit_to_unit(rate_limit)
        expected_price = pricing.calculate_price(quantity, product.unit_price)
        payload = self.build_floatingip_payload(
            self.floating_ip_address, rate_limit, project_id, id=resource_id)
        message = self.build_notification_message(
            self.admin_account.user_id, self.event_resized, payload,
            timestamp=end_time)
        handle = floatingip.FloatingIpCreateEnd()
        handle.change_unit_price(
            message, gring_const.STATE_RUNNING, order.order_id)
        order = self.dbconn.get_order(self.admin_req_context, order.order_id)
        self.assertDecimalEqual(expected_price, order.unit_price)
        subs_list = list(self.dbconn.get_subscriptions_by_order_id(
            self.admin_req_context, order.order_id))
        for subs in subs_list:
            self.assertEqual(quantity, subs.quantity)
Exemplo n.º 3
0
 def create_floatingip(self, rate_limit, project_id, timestamp=None):
     handle = floatingip.FloatingIpCreateEnd()
     payload = self.build_floatingip_payload(
         self.floating_ip_address, rate_limit, project_id)
     resource_id = payload['floatingip']['id']
     message = self.build_notification_message(
         self.admin_account.user_id, self.event_created, payload,
         timestamp=timestamp)
     handle.process_notification(message)
     return resource_id
Exemplo n.º 4
0
 def create_floatingipset(self, timestamp=None):
     handle = floatingip.FloatingIpCreateEnd()
     payload = self.build_floatingipset_payload(
         self.fipset, self.rate_limit, self.project_id)
     resource_id = payload['floatingipset']['id']
     message = self.build_notification_message(
         self.admin_account.user_id,
         floatingip.EVENT_FLOATINGIPSET_CREATE_END,
         payload, timestamp=timestamp)
     handle.process_notification(message)
     return resource_id, message
Exemplo n.º 5
0
    def test_fipset_change_unit_price_with_again_event(self):
        project_id = self.admin_account.project_id
        end_time = self.utcnow()
        start_time = end_time - datetime.timedelta(hours=1)

        # rate_limit = 1024
        rate_limit = 1024
        resource_id = self.create_floatingipset(
            rate_limit, project_id, timestamp=start_time)
        order = self.dbconn.get_order_by_resource_id(
            self.admin_req_context, resource_id)

        # change rate_limit to 1024 * 11
        rate_limit = 1024 * 11
        quantity = pricing.rate_limit_to_unit(rate_limit)
        expected_price = pricing.calculate_price(
            quantity, self.product.unit_price)

        payload = self.build_floatingipset_payload(
            self.fipset, rate_limit, self.admin_account.project_id)
        payload = payload['floatingipset']
        fipset = neutron.FloatingIpSet(
            id=payload['id'], name=payload['uos:name'],
            size=payload['rate_limit'], project_id=payload['tenant_id'],
            providers=payload['uos:service_provider'],
            resource_type=gring_const.RESOURCE_FLOATINGIPSET,
            status=payload['status'], is_reserved=True)
        message = fipset.to_message()

        handle = floatingip.FloatingIpCreateEnd()
        handle.change_unit_price(
            message, gring_const.STATE_RUNNING, order.order_id)
        order = self.dbconn.get_order(self.admin_req_context, order.order_id)
        self.assertDecimalEqual(expected_price, order.unit_price)
        subs_list = list(self.dbconn.get_subscriptions_by_order_id(
            self.admin_req_context, order.order_id))
        for subs in subs_list:
            self.assertEqual(quantity, subs.quantity)
Exemplo n.º 6
0
    def test_floatingip_get_unit_price(self):
        product = self.product_fixture.ip_products[0]
        rate_limit = 10240
        quantity = pricing.rate_limit_to_unit(rate_limit)
        expected_price = pricing.calculate_price(quantity, product.unit_price)

        payload = self.build_floatingip_payload(
            self.floating_ip_address, rate_limit,
            self.admin_account.project_id)
        message = self.build_notification_message(
            self.admin_account.user_id, self.event_created, payload)

        handle = floatingip.FloatingIpCreateEnd()
        handle.process_notification(message)

        resource_id = payload['floatingip']['id']
        order = self.dbconn.get_order_by_resource_id(
            self.admin_req_context, resource_id)

        price = handle.get_unit_price(order.order_id,
                                      message,
                                      gring_const.STATE_RUNNING)
        self.assertDecimalEqual(expected_price, price)