def test_fail_plugin(self): """ Testing not configured plugin """ with mock.patch( 'ralph_pricing.plugins.openstack.OpenStack') as OpenStack: OpenStack.side_effect = MockOpenStack status, message, arg = openstack_runner( today=datetime.datetime.today()) self.assertFalse(status)
def test_fail_plugin(self): """ Testing not configured plugin """ with mock.patch( 'ralph_pricing.plugins.openstack.OpenStack' ) as OpenStack: OpenStack.side_effect = MockOpenStack status, message, arg = openstack_runner( today=datetime.datetime.today() ) self.assertFalse(status)
def test_set_usages(self): """ OpenStack usages Test Case """ # fake setting need to run plugin settings.OPENSTACK_URL = '/' settings.OPENSTACK_USER = '******' settings.OPENSTACK_PASSWORD = '******' with mock.patch( 'ralph_pricing.plugins.openstack.OpenStack') as OpenStack: OpenStack.side_effect = MockOpenStack status, message, arg = openstack_runner( today=datetime.datetime.today()) self.assertTrue(status) # usages venture1 usage_venture1 = DailyUsage.objects.filter( pricing_venture__symbol='test_venture1', ) self.assertEqual(len(usage_venture1), 5) memory_usage_venture1 = usage_venture1.get( type__name='OpenStack 10000 Memory GiB Hours') volume_usage_venutre1 = usage_venture1.get( type__name='OpenStack 10000 Volume GiB Hours') vcpus_usage_venutre1 = usage_venture1.get( type__name='OpenStack 10000 CPU Hours') disk_usage_venutre1 = usage_venture1.get( type__name='OpenStack 10000 Disk GiB Hours') images_usage_venutre1 = usage_venture1.get( type__name='OpenStack 10000 Images GiB Hours') self.assertEqual(memory_usage_venture1.value, 393216.0 / 1024) self.assertEqual(volume_usage_venutre1.value, 480.0) self.assertEqual(vcpus_usage_venutre1.value, 192.0) self.assertEqual(disk_usage_venutre1.value, 768.0) self.assertEqual(images_usage_venutre1.value, 199.3) # usages venture2 usage_venture2 = DailyUsage.objects.filter( pricing_venture__symbol='test_venture2', ) self.assertEqual(len(usage_venture2), 5) memory_usage_venture2 = usage_venture2.get( type__name='OpenStack 10000 Memory GiB Hours') volume_usage_venutre2 = usage_venture2.get( type__name='OpenStack 10000 Volume GiB Hours') vcpus_usage_venutre2 = usage_venture2.get( type__name='OpenStack 10000 CPU Hours') disk_usage_venutre2 = usage_venture2.get( type__name='OpenStack 10000 Disk GiB Hours') images_usage_venutre2 = usage_venture2.get( type__name='OpenStack 10000 Images GiB Hours') self.assertEqual(memory_usage_venture2.value, 786432.0 / 1024) self.assertEqual(volume_usage_venutre2.value, 28800.0) self.assertEqual(vcpus_usage_venutre2.value, 384.0) self.assertEqual(disk_usage_venutre2.value, 1536.0) self.assertEqual(images_usage_venutre2.value, 315.0) # no data for venture3 usage_venture3 = DailyUsage.objects.filter( pricing_venture__symbol='test_venture3', ) self.assertEqual(len(usage_venture3), 0)
def test_set_usages(self): """ OpenStack usages Test Case """ # fake setting need to run plugin settings.OPENSTACK_URL = '/' settings.OPENSTACK_USER = '******' settings.OPENSTACK_PASSWORD = '******' with mock.patch( 'ralph_pricing.plugins.openstack.OpenStack' ) as OpenStack: OpenStack.side_effect = MockOpenStack status, message, arg = openstack_runner( today=datetime.datetime.today() ) self.assertTrue(status) # usages venture1 usage_venture1 = DailyUsage.objects.filter( pricing_venture__symbol='test_venture1', ) self.assertEqual(len(usage_venture1), 5) memory_usage_venture1 = usage_venture1.get( type__name='OpenStack 10000 Memory GiB Hours' ) volume_usage_venutre1 = usage_venture1.get( type__name='OpenStack 10000 Volume GiB Hours' ) vcpus_usage_venutre1 = usage_venture1.get( type__name='OpenStack 10000 CPU Hours' ) disk_usage_venutre1 = usage_venture1.get( type__name='OpenStack 10000 Disk GiB Hours' ) images_usage_venutre1 = usage_venture1.get( type__name='OpenStack 10000 Images GiB Hours' ) self.assertEqual(memory_usage_venture1.value, 393216.0 / 1024) self.assertEqual(volume_usage_venutre1.value, 480.0) self.assertEqual(vcpus_usage_venutre1.value, 192.0) self.assertEqual(disk_usage_venutre1.value, 768.0) self.assertEqual(images_usage_venutre1.value, 199.3) # usages venture2 usage_venture2 = DailyUsage.objects.filter( pricing_venture__symbol='test_venture2', ) self.assertEqual(len(usage_venture2), 5) memory_usage_venture2 = usage_venture2.get( type__name='OpenStack 10000 Memory GiB Hours' ) volume_usage_venutre2 = usage_venture2.get( type__name='OpenStack 10000 Volume GiB Hours' ) vcpus_usage_venutre2 = usage_venture2.get( type__name='OpenStack 10000 CPU Hours' ) disk_usage_venutre2 = usage_venture2.get( type__name='OpenStack 10000 Disk GiB Hours' ) images_usage_venutre2 = usage_venture2.get( type__name='OpenStack 10000 Images GiB Hours' ) self.assertEqual(memory_usage_venture2.value, 786432.0 / 1024) self.assertEqual(volume_usage_venutre2.value, 28800.0) self.assertEqual(vcpus_usage_venutre2.value, 384.0) self.assertEqual(disk_usage_venutre2.value, 1536.0) self.assertEqual(images_usage_venutre2.value, 315.0) # no data for venture3 usage_venture3 = DailyUsage.objects.filter( pricing_venture__symbol='test_venture3', ) self.assertEqual(len(usage_venture3), 0)