def test_compare(self): self.assertTrue(version._compare('1.0', version.gt('0.9'))) self.assertTrue(version._compare('1.0', version.ge('0.9'))) self.assertTrue(version._compare('1.0', version.ge('1.0'))) self.assertTrue(version._compare('1.0', version.eq('1.0'))) self.assertTrue(version._compare('1.0', version.le('1.0'))) self.assertTrue(version._compare('1.0', version.le('1.1'))) self.assertTrue(version._compare('1.0', version.lt('1.1'))) self.assertTrue( version._compare('1.1', version.gt('1.0'), version.lt('1.2'))) self.assertTrue( version._compare('0.3', version.eq('0.2'), version.eq('0.3'), op=any)) self.assertFalse(version._compare('1.0', version.gt('1.0'))) self.assertFalse(version._compare('1.0', version.ge('1.1'))) self.assertFalse(version._compare('1.0', version.eq('1.1'))) self.assertFalse(version._compare('1.0', version.le('0.9'))) self.assertFalse(version._compare('1.0', version.lt('0.9'))) self.assertRaises(ValueError, version._compare, 'abc', version.le('1.1')) self.assertRaises(ValueError, version._compare, '1.0', version.le('.0')) self.assertRaises(ValueError, version._compare, '1', version.le('2'))
def test_compare(self): self.assertTrue(version._compare('1.0', version.gt('0.9'))) self.assertTrue(version._compare('1.0', version.ge('0.9'))) self.assertTrue(version._compare('1.0', version.ge('1.0'))) self.assertTrue(version._compare('1.0', version.eq('1.0'))) self.assertTrue(version._compare('1.0', version.le('1.0'))) self.assertTrue(version._compare('1.0', version.le('1.1'))) self.assertTrue(version._compare('1.0', version.lt('1.1'))) self.assertTrue( version._compare('1.1', version.gt('1.0'), version.lt('1.2'))) self.assertTrue( version._compare('0.3', version.eq('0.2'), version.eq('0.3'), op=any)) # Test error message msg = 'Operation or argument is not supported with version 1.0; ' self.assertEqual((msg + 'requires version greater than 1.0'), version._compare('1.0', version.gt('1.0'))) self.assertEqual((msg + 'requires at least version 1.1'), version._compare('1.0', version.ge('1.1'))) self.assertEqual((msg + 'requires version 1.1'), version._compare('1.0', version.eq('1.1'))) self.assertEqual((msg + 'requires at most version 0.9'), version._compare('1.0', version.le('0.9'))) self.assertEqual((msg + 'requires version less than 0.9'), version._compare('1.0', version.lt('0.9'))) self.assertRaises(ValueError, version._compare, 'abc', version.le('1.1')) self.assertRaises(ValueError, version._compare, '1.0', version.le('.0')) self.assertRaises(ValueError, version._compare, '1', version.le('2')) ex = self.assertRaises(ValueError, version.compare, '1.0', version.ge('1.1')) self.assertEqual( 'Operation or argument is not supported with version 1.0; ' 'requires at least version 1.1', str(ex)) ex = self.assertRaises(ValueError, version.compare, '1.0', version.eq('1.1'), version.eq('1.5'), op=any) self.assertEqual( 'Operation or argument is not supported with version 1.0; ' 'requires version 1.1, or requires version 1.5', str(ex))
def test_check_mixin(self): class Test(version.CheckerMixin): app = mock.Mock() app.client_manager.placement.api_version = '1.2' t = Test() self.assertTrue(t.compare_version(version.le('1.3'))) self.assertTrue(t.check_version(version.ge('1.0'))) self.assertRaisesRegex(ValueError, 'Operation or argument is not supported', t.check_version, version.lt('1.2'))
def get_parser(self, prog_name): parser = super(DeleteInventory, self).get_parser(prog_name) parser.add_argument('uuid', metavar='<uuid>', help='UUID of the resource provider') parser.add_argument( '--resource-class', metavar='<resource_class>', required=self.compare_version(version.lt('1.5')), help=(RC_HELP + '\n' 'This argument can be omitted starting with ' '``--os-placement-api-version 1.5``. If it is omitted all ' 'inventories of the specified resource provider ' 'will be deleted.')) return parser
def take_action(self, parsed_args): http = self.app.client_manager.placement url = BASE_URL.format(uuid=parsed_args.uuid) aggregate = parsed_args.aggregate generation = None if 'generation' in parsed_args and parsed_args.generation is not None: self.check_version(version.ge('1.19')) generation = parsed_args.generation if self.compare_version(version.lt('1.19')): resp = http.request('PUT', url, json=aggregate).json() # Microversion 1.19 and beyond a generation argument is # required to write aggregates. elif generation is not None: data = { 'aggregates': aggregate, 'resource_provider_generation': generation } resp = http.request('PUT', url, json=data).json() else: raise exceptions.CommandError('A generation must be specified.') return FIELDS, [[r] for r in resp['aggregates']]