Ejemplo n.º 1
0
    def test_with_wrong_vcpu_size_in_content(self):
        instance_event = utils.get_instance_event()
        instance_event['content']['vcpu'] = 'size'
        self.post_json('/events', instance_event, expect_errors=True)

        instance_event['content']['vcpu'] = -10
        self.post_json('/events', instance_event, expect_errors=True)
Ejemplo n.º 2
0
    def test_power_off_resize_disk_exists_event_success(self):
        instance_event = utils.get_instance_event()
        instance_event['event_time'] = '2015-10-01T01:00:00.000000'
        instance_event['event_type'] = 'power_off'
        self.post_json('/events', instance_event)

        instance_event['event_time'] = '2015-10-11T01:00:00.000000'
        instance_event['content']['disk'] = 1000
        instance_event['event_type'] = 'resize'
        self.post_json('/events', instance_event)

        url = '/resources/' + instance_event['resource_id']
        res = self.get_json(url)
        self.assertEqual(int(res['consumption']), 240)
        self.assertEqual(res['status'], 'shutoff')

        url = '/records/' + instance_event['resource_id']
        records = self.get_json(url)
        self.assertEqual(len(records), 1)

        instance_event['event_time'] = '2015-10-21T01:00:00.000000'
        instance_event['event_type'] = 'exists'
        self.post_json('/events', instance_event)

        url = '/resources/' + instance_event['resource_id']
        res = self.get_json(url)
        self.assertEqual(int(res['consumption']), 240240)
        self.assertEqual(res['status'], 'shutoff')

        url = '/records/' + instance_event['resource_id']
        records = self.get_json(url)
        self.assertEqual(len(records), 2)
        self.assertEqual(int(records[0]['consumption']), 240)
        self.assertEqual(int(records[1]['consumption']), 240000)
Ejemplo n.º 3
0
    def test_exists_resize_delete_event_success(self):
        instance_event = utils.get_instance_event()
        instance_event['event_time'] = '2015-10-01T01:00:00.000000'
        instance_event['event_type'] = 'exists'
        self.post_json('/events', instance_event)

        instance_event['event_time'] = '2015-10-11T01:00:00.000000'
        instance_event['content']['vcpu'] = 1000
        instance_event['event_type'] = 'resize'
        self.post_json('/events', instance_event)

        url = '/resources/' + instance_event['resource_id']
        res = self.get_json(url)
        self.assertEqual(int(res['consumption']), 720)
        self.assertEqual(res['status'], 'active')

        url = '/records/' + instance_event['resource_id']
        records = self.get_json(url)
        self.assertEqual(len(records), 1)

        instance_event['event_time'] = '2015-10-21T01:00:00.000000'
        instance_event['event_type'] = 'delete'
        self.post_json('/events', instance_event)

        url = '/resources/' + instance_event['resource_id']
        res = self.get_json(url)
        self.assertEqual(int(res['consumption']), 241200)
        self.assertEqual(res['status'], 'delete')

        url = '/records/' + instance_event['resource_id']
        records = self.get_json(url)
        self.assertEqual(len(records), 2)
        self.assertEqual(int(records[0]['consumption']), 720)
        self.assertEqual(int(records[1]['consumption']), 240480)
Ejemplo n.º 4
0
    def test_create_power_off_delete_event_success(self):
        instance_event = utils.get_instance_event()
        instance_event['event_time'] = '2015-10-01T01:00:00.000000'
        self.post_json('/events', instance_event)

        instance_event['event_time'] = '2015-10-11T01:00:00.000000'
        instance_event['event_type'] = 'power_off'
        self.post_json('/events', instance_event)

        url = '/resources/' + instance_event['resource_id']
        res = self.get_json(url)
        self.assertEqual(int(res['consumption']), 720)
        self.assertEqual(res['status'], 'shutoff')

        url = '/records/' + instance_event['resource_id']
        records = self.get_json(url)
        self.assertEqual(len(records), 1)

        instance_event['event_time'] = '2015-10-21T01:00:00.000000'
        instance_event['event_type'] = 'delete'
        self.post_json('/events', instance_event)

        url = '/resources/' + instance_event['resource_id']
        res = self.get_json(url)
        self.assertEqual(int(res['consumption']), 960)
        self.assertEqual(res['status'], 'delete')

        url = '/records/' + instance_event['resource_id']
        records = self.get_json(url)
        self.assertEqual(len(records), 2)
        self.assertEqual(int(records[0]['consumption']), 720)
        self.assertEqual(int(records[1]['consumption']), 240)
Ejemplo n.º 5
0
    def test_exists_resize_delete_event_success(self):
        instance_event = utils.get_instance_event()
        instance_event['event_time'] = '2015-10-01T01:00:00.000000'
        instance_event['event_type'] = 'exists'
        self.post_json('/events', instance_event)

        instance_event['event_time'] = '2015-10-11T01:00:00.000000'
        instance_event['content']['vcpu'] = 1000
        instance_event['event_type'] = 'resize'
        self.post_json('/events', instance_event)

        url = '/resources/' + instance_event['resource_id']
        res = self.get_json(url)
        self.assertEqual(int(res['consumption']), 720)
        self.assertEqual(res['status'], 'active')

        url = '/records/' + instance_event['resource_id']
        records = self.get_json(url)
        self.assertEqual(len(records), 1)

        instance_event['event_time'] = '2015-10-21T01:00:00.000000'
        instance_event['event_type'] = 'delete'
        self.post_json('/events', instance_event)

        url = '/resources/' + instance_event['resource_id']
        res = self.get_json(url)
        self.assertEqual(int(res['consumption']), 241200)
        self.assertEqual(res['status'], 'delete')

        url = '/records/' + instance_event['resource_id']
        records = self.get_json(url)
        self.assertEqual(len(records), 2)
        self.assertEqual(int(records[0]['consumption']), 720)
        self.assertEqual(int(records[1]['consumption']), 240480)
Ejemplo n.º 6
0
    def test_create_power_off_delete_event_success(self):
        instance_event = utils.get_instance_event()
        instance_event['event_time'] = '2015-10-01T01:00:00.000000'
        self.post_json('/events', instance_event)

        instance_event['event_time'] = '2015-10-11T01:00:00.000000'
        instance_event['event_type'] = 'power_off'
        self.post_json('/events', instance_event)

        url = '/resources/' + instance_event['resource_id']
        res = self.get_json(url)
        self.assertEqual(int(res['consumption']), 720)
        self.assertEqual(res['status'], 'shutoff')

        url = '/records/' + instance_event['resource_id']
        records = self.get_json(url)
        self.assertEqual(len(records), 1)

        instance_event['event_time'] = '2015-10-21T01:00:00.000000'
        instance_event['event_type'] = 'delete'
        self.post_json('/events', instance_event)

        url = '/resources/' + instance_event['resource_id']
        res = self.get_json(url)
        self.assertEqual(int(res['consumption']), 960)
        self.assertEqual(res['status'], 'delete')

        url = '/records/' + instance_event['resource_id']
        records = self.get_json(url)
        self.assertEqual(len(records), 2)
        self.assertEqual(int(records[0]['consumption']), 720)
        self.assertEqual(int(records[1]['consumption']), 240)
Ejemplo n.º 7
0
    def test_with_wrong_vcpu_size_in_content(self):
        instance_event = utils.get_instance_event()
        instance_event['content']['vcpu'] = 'size'
        self.post_json('/events', instance_event, expect_errors=True)

        instance_event['content']['vcpu'] = -10
        self.post_json('/events', instance_event, expect_errors=True)
Ejemplo n.º 8
0
    def test_create_delete_create_event_success(self):
        instance_event = utils.get_instance_event()
        instance_event['event_time'] = '2015-10-01T01:00:00.000000'
        instance_event['event_type'] = 'create'
        self.post_json('/events', instance_event)

        instance_event['event_time'] = '2015-10-11T01:00:00.000000'
        instance_event['event_type'] = 'delete'
        self.post_json('/events', instance_event)

        url = '/resources/' + instance_event['resource_id']
        res = self.get_json(url)
        self.assertEqual(int(res['consumption']), 720)
        self.assertEqual(res['status'], 'delete')

        url = '/records/' + instance_event['resource_id']
        records = self.get_json(url)
        self.assertEqual(len(records), 1)

        instance_event['event_time'] = '2015-10-21T01:00:00.000000'
        instance_event['event_type'] = 'exists'
        self.post_json('/events', instance_event, expect_errors=True)

        url = '/resources/' + instance_event['resource_id']
        res = self.get_json(url)
        self.assertEqual(int(res['consumption']), 720)
        self.assertEqual(res['status'], 'delete')

        url = '/records/' + instance_event['resource_id']
        records = self.get_json(url)
        self.assertEqual(len(records), 1)
        self.assertEqual(int(records[0]['consumption']), 720)
Ejemplo n.º 9
0
    def test_create_exists_delete_with_missing_resize(self):
        instance_event = utils.get_instance_event()
        instance_event['event_time'] = '2015-10-01T01:00:00.000000'
        instance_event['event_type'] = 'create'
        self.post_json('/events', instance_event)

        instance_event['event_time'] = '2015-10-11T01:00:00.000000'
        # Missing resize event
        instance_event['content']['vcpu'] = 1000
        instance_event['event_type'] = 'exists'
        self.post_json('/events', instance_event)

        url = '/resources/' + instance_event['resource_id']
        res = self.get_json(url)
        self.assertEqual(int(res['consumption']), 720)

        instance_event['event_time'] = '2015-10-21T01:00:00.000000'
        instance_event['event_type'] = 'delete'
        self.post_json('/events', instance_event)

        url = '/resources/' + instance_event['resource_id']
        res = self.get_json(url)
        self.assertEqual(int(res['consumption']), 241200)

        url = '/records/' + instance_event['resource_id']
        records = self.get_json(url)
        self.assertEqual(len(records), 2)
        self.assertEqual(int(records[0]['consumption']), 720)
        self.assertEqual(int(records[1]['consumption']), 240480)
Ejemplo n.º 10
0
    def test_create_delete_create_event_success(self):
        instance_event = utils.get_instance_event()
        instance_event['event_time'] = '2015-10-01T01:00:00.000000'
        instance_event['event_type'] = 'create'
        self.post_json('/events', instance_event)

        instance_event['event_time'] = '2015-10-11T01:00:00.000000'
        instance_event['event_type'] = 'delete'
        self.post_json('/events', instance_event)

        url = '/resources/' + instance_event['resource_id']
        res = self.get_json(url)
        self.assertEqual(int(res['consumption']), 720)
        self.assertEqual(res['status'], 'delete')

        url = '/records/' + instance_event['resource_id']
        records = self.get_json(url)
        self.assertEqual(len(records), 1)

        instance_event['event_time'] = '2015-10-21T01:00:00.000000'
        instance_event['event_type'] = 'exists'
        self.post_json('/events', instance_event, expect_errors=True)

        url = '/resources/' + instance_event['resource_id']
        res = self.get_json(url)
        self.assertEqual(int(res['consumption']), 720)
        self.assertEqual(res['status'], 'delete')

        url = '/records/' + instance_event['resource_id']
        records = self.get_json(url)
        self.assertEqual(len(records), 1)
        self.assertEqual(int(records[0]['consumption']), 720)
Ejemplo n.º 11
0
    def test_power_off_resize_disk_exists_event_success(self):
        instance_event = utils.get_instance_event()
        instance_event['event_time'] = '2015-10-01T01:00:00.000000'
        instance_event['event_type'] = 'power_off'
        self.post_json('/events', instance_event)

        instance_event['event_time'] = '2015-10-11T01:00:00.000000'
        instance_event['content']['disk'] = 1000
        instance_event['event_type'] = 'resize'
        self.post_json('/events', instance_event)

        url = '/resources/' + instance_event['resource_id']
        res = self.get_json(url)
        self.assertEqual(int(res['consumption']), 240)
        self.assertEqual(res['status'], 'shutoff')

        url = '/records/' + instance_event['resource_id']
        records = self.get_json(url)
        self.assertEqual(len(records), 1)

        instance_event['event_time'] = '2015-10-21T01:00:00.000000'
        instance_event['event_type'] = 'exists'
        self.post_json('/events', instance_event)

        url = '/resources/' + instance_event['resource_id']
        res = self.get_json(url)
        self.assertEqual(int(res['consumption']), 240240)
        self.assertEqual(res['status'], 'shutoff')

        url = '/records/' + instance_event['resource_id']
        records = self.get_json(url)
        self.assertEqual(len(records), 2)
        self.assertEqual(int(records[0]['consumption']), 240)
        self.assertEqual(int(records[1]['consumption']), 240000)
Ejemplo n.º 12
0
    def test_create_exists_delete_with_missing_resize(self):
        instance_event = utils.get_instance_event()
        instance_event['event_time'] = '2015-10-01T01:00:00.000000'
        instance_event['event_type'] = 'create'
        self.post_json('/events', instance_event)

        instance_event['event_time'] = '2015-10-11T01:00:00.000000'
        # Missing resize event
        instance_event['content']['vcpu'] = 1000
        instance_event['event_type'] = 'exists'
        self.post_json('/events', instance_event)

        url = '/resources/' + instance_event['resource_id']
        res = self.get_json(url)
        self.assertEqual(int(res['consumption']), 720)

        instance_event['event_time'] = '2015-10-21T01:00:00.000000'
        instance_event['event_type'] = 'delete'
        self.post_json('/events', instance_event)

        url = '/resources/' + instance_event['resource_id']
        res = self.get_json(url)
        self.assertEqual(int(res['consumption']), 241200)

        url = '/records/' + instance_event['resource_id']
        records = self.get_json(url)
        self.assertEqual(len(records), 2)
        self.assertEqual(int(records[0]['consumption']), 720)
        self.assertEqual(int(records[1]['consumption']), 240480)
Ejemplo n.º 13
0
    def test_with_wrong_event_time(self):
        instance_event = utils.get_instance_event()
        instance_event['event_time'] = '2015-10-01T01:00:00.000000'
        self.post_json('/events', instance_event)

        instance_event['event_time'] = '2015-09-11T01:00:00.000000'
        instance_event['event_type'] = 'exists'
        self.post_json('/events', instance_event, expect_errors=True)
Ejemplo n.º 14
0
    def test_with_wrong_event_time(self):
        instance_event = utils.get_instance_event()
        instance_event['event_time'] = '2015-10-01T01:00:00.000000'
        self.post_json('/events', instance_event)

        instance_event['event_time'] = '2015-09-11T01:00:00.000000'
        instance_event['event_type'] = 'exists'
        self.post_json('/events', instance_event, expect_errors=True)
Ejemplo n.º 15
0
    def test_post_delete_event_success(self):
        instance_event = utils.get_instance_event()
        instance_event['event_type'] = 'delete'
        self.post_json('/events', instance_event)

        url = '/resources/' + instance_event['resource_id']
        self.get_json(url, expect_errors=True)

        url = '/records/' + instance_event['resource_id']
        self.get_json(url, expect_errors=True)
Ejemplo n.º 16
0
    def test_post_create_event_success(self):
        instance_event = utils.get_instance_event()
        self.post_json('/events', instance_event)

        url = '/resources/' + instance_event['resource_id']
        res = self.get_json(url)
        self.assertEqual(res['status'], 'active')

        url = '/records/' + instance_event['resource_id']
        self.get_json(url, expect_errors=True)
Ejemplo n.º 17
0
    def test_post_create_event_success(self):
        instance_event = utils.get_instance_event()
        self.post_json('/events', instance_event)

        url = '/resources/' + instance_event['resource_id']
        res = self.get_json(url)
        self.assertEqual(res['status'], 'active')

        url = '/records/' + instance_event['resource_id']
        self.get_json(url, expect_errors=True)
Ejemplo n.º 18
0
    def test_post_delete_event_success(self):
        instance_event = utils.get_instance_event()
        instance_event['event_type'] = 'delete'
        self.post_json('/events', instance_event)

        url = '/resources/' + instance_event['resource_id']
        self.get_json(url, expect_errors=True)

        url = '/records/' + instance_event['resource_id']
        self.get_json(url, expect_errors=True)
Ejemplo n.º 19
0
    def test_post_shut_off_event_success(self):
        instance_event = utils.get_instance_event()
        instance_event['event_type'] = 'power_off'
        self.post_json('/events', instance_event)

        url = '/resources/' + instance_event['resource_id']
        res = self.get_json(url)
        self.assertEqual(res['status'], 'shutoff')

        url = '/records/' + instance_event['resource_id']
        self.get_json(url, expect_errors=True)
Ejemplo n.º 20
0
    def test_post_shut_off_event_success(self):
        instance_event = utils.get_instance_event()
        instance_event['event_type'] = 'power_off'
        self.post_json('/events', instance_event)

        url = '/resources/' + instance_event['resource_id']
        res = self.get_json(url)
        self.assertEqual(res['status'], 'shutoff')

        url = '/records/' + instance_event['resource_id']
        self.get_json(url, expect_errors=True)
Ejemplo n.º 21
0
    def test_power_off_and_power_on_event_success(self):
        instance_event = utils.get_instance_event()
        instance_event['event_time'] = '2015-10-01T01:00:00.000000'
        instance_event['event_type'] = 'power_off'
        self.post_json('/events', instance_event)

        instance_event['event_time'] = '2015-10-11T01:00:00.000000'
        instance_event['event_type'] = 'power_on'
        self.post_json('/events', instance_event)

        url = '/resources/' + instance_event['resource_id']
        res = self.get_json(url)
        self.assertEqual(int(res['consumption']), 240)
        self.assertEqual(res['status'], 'active')

        url = '/records/' + instance_event['resource_id']
        records = self.get_json(url)
        self.assertEqual(len(records), 1)
        self.assertEqual(int(records[0]['consumption']), 240)
Ejemplo n.º 22
0
    def test_power_off_and_power_on_event_success(self):
        instance_event = utils.get_instance_event()
        instance_event['event_time'] = '2015-10-01T01:00:00.000000'
        instance_event['event_type'] = 'power_off'
        self.post_json('/events', instance_event)

        instance_event['event_time'] = '2015-10-11T01:00:00.000000'
        instance_event['event_type'] = 'power_on'
        self.post_json('/events', instance_event)

        url = '/resources/' + instance_event['resource_id']
        res = self.get_json(url)
        self.assertEqual(int(res['consumption']), 240)
        self.assertEqual(res['status'], 'active')

        url = '/records/' + instance_event['resource_id']
        records = self.get_json(url)
        self.assertEqual(len(records), 1)
        self.assertEqual(int(records[0]['consumption']), 240)
Ejemplo n.º 23
0
 def test_without_resource_id(self):
     instance_event = utils.get_instance_event()
     instance_event.pop('resource_id')
     self.post_json('/events', instance_event, expect_errors=True)
Ejemplo n.º 24
0
 def test_wrong_event_type(self):
     instance_event = utils.get_instance_event()
     instance_event['event_type'] = 'wrong_event_type'
     self.post_json('/events', instance_event, expect_errors=True)
Ejemplo n.º 25
0
 def test_without_vcpu_in_content(self):
     instance_event = utils.get_instance_event()
     instance_event['content'].pop('vcpu')
     self.post_json('/events', instance_event, expect_errors=True)
Ejemplo n.º 26
0
 def test_without_vcpu_in_content(self):
     instance_event = utils.get_instance_event()
     instance_event['content'].pop('vcpu')
     self.post_json('/events', instance_event, expect_errors=True)
Ejemplo n.º 27
0
 def test_without_resource_id(self):
     instance_event = utils.get_instance_event()
     instance_event.pop('resource_id')
     self.post_json('/events', instance_event, expect_errors=True)
Ejemplo n.º 28
0
 def test_wrong_event_type(self):
     instance_event = utils.get_instance_event()
     instance_event['event_type'] = 'wrong_event_type'
     self.post_json('/events', instance_event, expect_errors=True)