def test_validate_deploy_children(self): _validate_deploy_children('deadbeefcafe', 0) parent = Device.create( ethernets=[('', 'deadbeefcafe', 0)], model_name='splat', model_type=DeviceType.unknown, ) _validate_deploy_children('deadbeefcafe', 0) device = Device.create( ethernets=[('', 'cafedeadbeef', 0)], model_name='splat', model_type=DeviceType.unknown, parent=parent, ) with self.assertRaises(forms.ValidationError): _validate_deploy_children('deadbeefcafe', 0) device.parent = None device.save() _validate_deploy_children('deadbeefcafe', 0) _validate_deploy_children('cafedeadbeef', 0) share = DiskShare(wwn='a' * 33, device=parent) share.save() mount = DiskShareMount(share=share, device=device, server=device) mount.save() with self.assertRaises(forms.ValidationError): _validate_deploy_children('deadbeefcafe', 0) with self.assertRaises(forms.ValidationError): _validate_deploy_children('cafedeadbeef', 0)
def test_validate_deploy_children(self): _validate_deploy_children('deadbeefcafe', 0) parent = Device.create( ethernets=[('', 'deadbeefcafe', 0)], model_name='splat', model_type=DeviceType.unknown, ) _validate_deploy_children('deadbeefcafe', 0) device = Device.create( ethernets=[('', 'cafedeadbeef', 0)], model_name='splat', model_type=DeviceType.unknown, parent=parent, ) with self.assertRaises(forms.ValidationError): _validate_deploy_children('deadbeefcafe', 0) device.parent = None device.save() _validate_deploy_children('deadbeefcafe', 0) _validate_deploy_children('cafedeadbeef', 0) share = DiskShare(wwn='a' * 33, device=parent) share.save() mount = DiskShareMount(share=share, device=device, server=device) mount.save() with self.assertRaises(forms.ValidationError): _validate_deploy_children('deadbeefcafe', 0) with self.assertRaises(forms.ValidationError): _validate_deploy_children('cafedeadbeef', 0)
def _create_or_update_share_mount(ip, device, share_mount): share_address = None if share_mount.get('address'): try: share_address = IPAddress.objects.get( address=share_mount['address']) except IPAddress.DoesNotExist: pass try: share = DiskShare.objects.get(wwn=share_mount['serial_number']) except DiskShare.DoesNotExist: logger.warning( '%s%sNo share found for share mount: ' 'WWN=%s; Volume=%s; device=%s; venture=%s; device_ip=%s' % ('(3PAR) ' if _it_is_3par(share_mount['serial_number']) else '', '(virtual) ' if share_mount.get('is_virtual', False) else '', share_mount['serial_number'], share_mount.get('volume'), device, device.venture, ip.address)) return False, None try: mount = DiskShareMount.objects.get(device=device, share=share) except DiskShareMount.DoesNotExist: mount = DiskShareMount( device=device, share=share, ) logger.info( '%s%sCreate mount point on device %s (venture=%s). ' 'Share WWN=%s; Volume=%s; Share label=%s; IP address=%s' % ('(3PAR) ' if _it_is_3par(share_mount['serial_number']) else '', '(virtual) ' if share_mount.get('is_virtual', False) else '', device, device.venture, share_mount['serial_number'], share_mount.get('volume'), share.label, ip.address)) else: logger.info( '%s%sMount point on device %s (venture=%s) exists. ' 'Share WWN=%s; Volume=%s; Share label=%s; IP address=%s' % ('(3PAR) ' if _it_is_3par(share_mount['serial_number']) else '', '(virtual) ' if share_mount.get('is_virtual', False) else '', device, device.venture, share_mount['serial_number'], share_mount.get('volume'), share.label, ip.address)) if share_mount.get('size'): mount.size = share_mount['size'] if share_mount.get('volume'): mount.volume = share_mount['volume'] if share_address: mount.address = share_address mount.is_virtual = share_mount.get('is_virtual', False) mount.save() return True, mount
def test_disk_share(self): storage_dev = Device.create( sn='device', model_type=DeviceType.storage, model_name='storage device', ) storage_dev.save() share_group = ComponentModelGroup( price=1, type=ComponentType.share, per_size=False, size_unit='', size_modifier=1, ) share_group.save() share_model = ComponentModel( speed=0, cores=0, size=7, type=ComponentType.share, group=share_group, family='', ) share_model.save() disk_share = DiskShare( device=storage_dev, model=share_model, share_id=1, label="share", size=7, snapshot_size=5, wwn='123456789012345678901234567890123', full=True, ) disk_share.save() share_mount = DiskShareMount( share=disk_share, device=storage_dev, size=17, ) share_mount.save() today = date.today() this_month = date(year=today.year, month=today.month, day=1) pricing_group = PricingGroup( name='group', date=this_month, ) pricing_group.save() pricing_group.devices.add(storage_dev) pricing_group.save() pricing_formula = PricingFormula( group=pricing_group, component_group=share_group, formula='3+size+11*variable', ) pricing_formula.save() pricing_variable = PricingVariable( name='variable', group=pricing_group, aggregate=PricingAggregate.sum, ) pricing_variable.save() pricing_value = PricingValue( device=storage_dev, variable=pricing_variable, value=13, ) pricing_value.save() variable_value = pricing_variable.get_value() self.assertEqual(variable_value, 13) formula_value = pricing_formula.get_value(size=7) self.assertEqual(formula_value, 3 + 7 + 11 * 13) share_price = disk_share.get_price() self.assertEqual(share_price, 3 + (7.0 + 5.0) / 1024 + 11 * 13) mount_price = share_mount.get_price() self.assertEqual(mount_price, 3 + 17.0 / 1024 + 11 * 13)
def _create_or_update_share_mount(ip, device, share_mount): share_address = None if share_mount.get('address'): try: share_address = IPAddress.objects.get( address=share_mount['address'] ) except IPAddress.DoesNotExist: pass try: share = DiskShare.objects.get( wwn=share_mount['serial_number'] ) except DiskShare.DoesNotExist: logger.warning( '%s%sNo share found for share mount: ' 'WWN=%s; Volume=%s; device=%s; venture=%s; device_ip=%s' % ( '(3PAR) ' if _it_is_3par( share_mount['serial_number'] ) else '', '(virtual) ' if share_mount.get( 'is_virtual', False ) else '', share_mount['serial_number'], share_mount.get('volume'), device, device.venture, ip.address ) ) return False, None try: mount = DiskShareMount.objects.get(device=device, share=share) except DiskShareMount.DoesNotExist: mount = DiskShareMount( device=device, share=share, ) logger.info( '%s%sCreate mount point on device %s (venture=%s). ' 'Share WWN=%s; Volume=%s; Share label=%s; IP address=%s' % ( '(3PAR) ' if _it_is_3par( share_mount['serial_number'] ) else '', '(virtual) ' if share_mount.get( 'is_virtual', False ) else '', device, device.venture, share_mount['serial_number'], share_mount.get('volume'), share.label, ip.address ) ) else: logger.info( '%s%sMount point on device %s (venture=%s) exists. ' 'Share WWN=%s; Volume=%s; Share label=%s; IP address=%s' % ( '(3PAR) ' if _it_is_3par( share_mount['serial_number'] ) else '', '(virtual) ' if share_mount.get( 'is_virtual', False ) else '', device, device.venture, share_mount['serial_number'], share_mount.get('volume'), share.label, ip.address ) ) if share_mount.get('size'): mount.size = share_mount['size'] if share_mount.get('volume'): mount.volume = share_mount['volume'] if share_address: mount.address = share_address mount.is_virtual = share_mount.get('is_virtual', False) mount.save() return True, mount
def test_disk_share(self): storage_dev = Device.create( sn='device', model_type=DeviceType.storage, model_name='storage device', ) storage_dev.save() share_group = ComponentModelGroup( price=1, type=ComponentType.share, per_size=False, size_unit='', size_modifier=1, ) share_group.save() share_model = ComponentModel( speed=0, cores=0, size=7, type=ComponentType.share, group=share_group, family='', ) share_model.save() disk_share = DiskShare( device=storage_dev, model=share_model, share_id=1, label="share", size=7, snapshot_size=5, wwn='123456789012345678901234567890123', full=True, ) disk_share.save() share_mount = DiskShareMount( share=disk_share, device=storage_dev, size=17, ) share_mount.save() today = date.today() this_month = date(year=today.year, month=today.month, day=1) pricing_group = PricingGroup( name='group', date=this_month, ) pricing_group.save() pricing_group.devices.add(storage_dev) pricing_group.save() pricing_formula = PricingFormula( group=pricing_group, component_group=share_group, formula='3+size+11*variable', ) pricing_formula.save() pricing_variable = PricingVariable( name='variable', group=pricing_group, aggregate=PricingAggregate.sum, ) pricing_variable.save() pricing_value = PricingValue( device=storage_dev, variable=pricing_variable, value=13, ) pricing_value.save() variable_value = pricing_variable.get_value() self.assertEqual(variable_value, 13) formula_value = pricing_formula.get_value(size=7) self.assertEqual(formula_value, 3 + 7 + 11 * 13) share_price = disk_share.get_price() self.assertEqual(share_price, 3 + (7.0 + 5.0) / 1024 + 11 * 13) mount_price = share_mount.get_price() self.assertEqual(mount_price, 3 + 17.0 / 1024 + 11 * 13)