Validate rxtx_factor as a float.
Updates the rxtx_factor validations in the instance_types modules so that rxtx_factor is validated as a float. Given that rxtx_factor is stored as a float in the database this makes sense... and also adheres to some of the extension documentation as well (although some of the extension docs were incorrect as well). Previously rxtx_factor was being cast into an int which caused it to be stored and displayed incorrectly via the API. This patchset adds a test which fails with the old code. Additionally some of the API docs are corrected so that rxtx_factor is listed as a float in all examples. Fixes LP Bug #1081287. Change-Id: Iae98522a1f2ed63cbd2497b0b0af5ac2d9bb935c
This commit is contained in:
		@@ -808,7 +808,7 @@ class InstanceTypeCommands(object):
 | 
			
		||||
    @args('--is_public', dest="is_public", metavar='<is_public>',
 | 
			
		||||
            help='Make flavor accessible to the public')
 | 
			
		||||
    def create(self, name, memory, vcpus, root_gb, ephemeral_gb=0,
 | 
			
		||||
               flavorid=None, swap=0, rxtx_factor=1, is_public=True):
 | 
			
		||||
               flavorid=None, swap=0, rxtx_factor=1.0, is_public=True):
 | 
			
		||||
        """Creates instance types / flavors"""
 | 
			
		||||
        try:
 | 
			
		||||
            instance_types.create(name, memory, vcpus, root_gb,
 | 
			
		||||
 
 | 
			
		||||
@@ -5,8 +5,8 @@
 | 
			
		||||
        "id": "666",
 | 
			
		||||
        "name": "flavortest",
 | 
			
		||||
        "ram": 1024,
 | 
			
		||||
        "rxtx_factor": 2,
 | 
			
		||||
        "rxtx_factor": 2.0,
 | 
			
		||||
        "swap": 5,
 | 
			
		||||
        "vcpus": 2
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -7,5 +7,5 @@
 | 
			
		||||
    disk="10"
 | 
			
		||||
    id="666"
 | 
			
		||||
    swap="5"
 | 
			
		||||
    rxtx_factor="2"
 | 
			
		||||
    OS-FLV-EXT-DATA:ephemeral="30" />
 | 
			
		||||
    rxtx_factor="2.0"
 | 
			
		||||
    OS-FLV-EXT-DATA:ephemeral="30" />
 | 
			
		||||
 
 | 
			
		||||
@@ -21,4 +21,4 @@
 | 
			
		||||
        "swap": "",
 | 
			
		||||
        "vcpus": 1
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -71,7 +71,7 @@ class InstanceTypeTestCase(test.TestCase):
 | 
			
		||||
        self.assertEqual(inst_type['root_gb'], 120)
 | 
			
		||||
        self.assertEqual(inst_type['ephemeral_gb'], 0)
 | 
			
		||||
        self.assertEqual(inst_type['swap'], 0)
 | 
			
		||||
        self.assertEqual(inst_type['rxtx_factor'], 1)
 | 
			
		||||
        self.assertEqual(inst_type['rxtx_factor'], 1.0)
 | 
			
		||||
 | 
			
		||||
        # make sure new type shows up in list
 | 
			
		||||
        new_list = instance_types.get_all_types()
 | 
			
		||||
@@ -95,7 +95,7 @@ class InstanceTypeTestCase(test.TestCase):
 | 
			
		||||
        self.assertEqual(inst_type['root_gb'], 120)
 | 
			
		||||
        self.assertEqual(inst_type['ephemeral_gb'], 100)
 | 
			
		||||
        self.assertEqual(inst_type['swap'], 0)
 | 
			
		||||
        self.assertEqual(inst_type['rxtx_factor'], 1)
 | 
			
		||||
        self.assertEqual(inst_type['rxtx_factor'], 1.0)
 | 
			
		||||
 | 
			
		||||
        # make sure new type shows up in list
 | 
			
		||||
        new_list = instance_types.get_all_types()
 | 
			
		||||
@@ -120,7 +120,20 @@ class InstanceTypeTestCase(test.TestCase):
 | 
			
		||||
        self.assertEqual(inst_type['root_gb'], 120)
 | 
			
		||||
        self.assertEqual(inst_type['ephemeral_gb'], 100)
 | 
			
		||||
        self.assertEqual(inst_type['swap'], 0)
 | 
			
		||||
        self.assertEqual(inst_type['rxtx_factor'], 1)
 | 
			
		||||
        self.assertEqual(inst_type['rxtx_factor'], 1.0)
 | 
			
		||||
 | 
			
		||||
    def test_instance_type_create_with_custom_rxtx_factor(self):
 | 
			
		||||
        name = 'Custom RXTX Factor'
 | 
			
		||||
        inst_type = instance_types.create(name, 256, 1, 120, 100,
 | 
			
		||||
                                          rxtx_factor=9.9)
 | 
			
		||||
        self.assertNotEqual(inst_type['flavorid'], None)
 | 
			
		||||
        self.assertEqual(inst_type['name'], name)
 | 
			
		||||
        self.assertEqual(inst_type['memory_mb'], 256)
 | 
			
		||||
        self.assertEqual(inst_type['vcpus'], 1)
 | 
			
		||||
        self.assertEqual(inst_type['root_gb'], 120)
 | 
			
		||||
        self.assertEqual(inst_type['ephemeral_gb'], 100)
 | 
			
		||||
        self.assertEqual(inst_type['swap'], 0)
 | 
			
		||||
        self.assertEqual(inst_type['rxtx_factor'], 9.9)
 | 
			
		||||
 | 
			
		||||
    def test_instance_type_create_with_special_characters(self):
 | 
			
		||||
        """Ensure instance types raises InvalidInput for invalid characters"""
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user