Beispiel #1
0
 def test_disk_shares_and_exports(self):
     model = ComponentModel(
         type=ComponentType.share,
         name="3par share",
     )
     model.save()
     share = DiskShare(
         device=self.device,
         model=model,
         label="pr0n",
         size="2048",
         wwn="deadbeefcafe1234",
     )
     share.save()
     address = IPAddress(address='127.0.0.1')
     address.save()
     DiskShareMount(
         device=self.device,
         share=share,
         address=address,
     ).save()
     data = get_device_data(Device.objects.get(sn='123456789'))
     exports = data['disk_exports']
     mounts = data['disk_shares']
     self.assertEqual(len(exports), 1)
     self.assertEqual(len(mounts), 1)
     self.assertEqual(mounts[0]['serial_number'], "deadbeefcafe1234")
Beispiel #2
0
 def test_disk_shares_and_exports(self):
     model = ComponentModel(
         type=ComponentType.share,
         name="3par share",
     )
     model.save()
     share = DiskShare(
         device=self.device,
         model=model,
         label="pr0n",
         size="2048",
         wwn="deadbeefcafe1234",
     )
     share.save()
     address = IPAddress(address='127.0.0.1')
     address.save()
     DiskShareMount(
         device=self.device,
         share=share,
         address=address,
     ).save()
     data = get_device_data(Device.objects.get(sn='123456789'))
     exports = data['disk_exports']
     mounts = data['disk_shares']
     self.assertEqual(len(exports), 1)
     self.assertEqual(len(mounts), 1)
     self.assertEqual(mounts[0]['serial_number'], "deadbeefcafe1234")
Beispiel #3
0
 def test_name(self):
     ip = IPAddress(address='127.0.0.1')
     ip.save()
     with mock.patch('ralph.discovery.plugins.snmp.snmp_command') as snmp_command:
         snmp_command.return_value = [[None, b'Testing name']]
         is_up, message = snmp._snmp('127.0.0.1', 'public', (1,3,6,1,2,1,1,1,0))
     self.assertEqual(message, 'Testing name')
     self.assertEqual(is_up, True)
Beispiel #4
0
 def test_ip_is_public_or_no(self):
     ip_list = [
         ('92.143.123.123', True),
         ('10.168.123.123', False),
     ]
     for ip, is_public in ip_list:
         new_ip_address = IPAddress(address=ip)
         new_ip_address.save()
         self.assertEquals(new_ip_address.is_public, is_public)
Beispiel #5
0
class ApiPricingTest(TestCase):

    def setUp(self):
        self.venture, created = Venture.objects.get_or_create(
            name="Sample venture",
        )
        self.venture.save()

        self.device, created = Device.objects.get_or_create(
            name="Device1",
            venture=self.venture,
        )
        self.device_without_venture, created = Device.objects.get_or_create(
            name="Device2",
        )

        self.ip1 = IPAddress(address='1.1.1.1', device=self.device)
        self.ip2 = IPAddress(address='2.2.2.2', venture=self.venture)
        self.ip1.save()
        self.ip2.save()

        self.device.save()
        self.device_without_venture.save()

    def test_get_device_by_name_with_venture(self):
        # device with venture
        device1 = api_pricing.get_device_by_name("Device1")
        self.assertEqual(device1['device_id'], self.device.id)
        self.assertEqual(device1['venture_id'], self.venture.id)

    def test_get_device_by_name_without_venture(self):
        # device without venture
        device2 = api_pricing.get_device_by_name("Device2")
        self.assertEqual(device2['device_id'], self.device_without_venture.id)
        self.assertIsNone(device2['venture_id'])

    def test_get_device_by_name_wrong_name(self):
        # device does not exist
        device3 = api_pricing.get_device_by_name("Device3")
        self.assertEqual(device3, {})

    def test_get_ip_info(self):
        result = api_pricing.get_ip_info(ipaddress='1.1.1.1')
        self.assertEquals(result, {
            'device_id': self.device.id,
            'venture_id': self.venture.id,
        })

    def test_get_ip_info_without_device(self):
        result = api_pricing.get_ip_info(ipaddress='2.2.2.2')
        self.assertEquals(result, {
            'venture_id': self.venture.id,
        })

    def test_get_ip_info_empty(self):
        result = api_pricing.get_ip_info(ipaddress='3.3.3.3')
        self.assertEquals(result, {})
 def test_ip_is_public_or_no(self):
     ip_list = [
         ('92.143.123.123', True),
         ('10.168.123.123', False),
     ]
     for ip, is_public in ip_list:
         new_ip_address = IPAddress(address=ip)
         new_ip_address.save()
         self.assertEquals(new_ip_address.is_public, is_public)
Beispiel #7
0
 def test_name(self):
     ip = IPAddress(address='127.0.0.1')
     ip.save()
     with mock.patch(
             'ralph.discovery.plugins.snmp.snmp_command') as snmp_command:
         snmp_command.return_value = [[None, b'Testing name']]
         is_up, message = snmp._snmp('127.0.0.1', 'public',
                                     (1, 3, 6, 1, 2, 1, 1, 1, 0))
     self.assertEqual(message, 'Testing name')
     self.assertEqual(is_up, True)
Beispiel #8
0
def _ip_create_record(form, request, device):
    hostname = form.cleaned_data.get('ip_new_hostname')
    address = form.cleaned_data.get('ip_new_address')
    if hostname and address:
        if IPAddress.objects.filter(address=address).exists():
            messages.error(
                request,
                "An IP address entry for %s already exists." % address)
            return
        record = IPAddress(address=address, hostname=hostname, device=device)
        record.save()
        messages.success(request,
                         "An IP address entry for %s created." % address)
Beispiel #9
0
class CleanPluginTest(TestCase):
    def setUp(self):
        device = Device.create(
            ethernets=[('', 'deadbeefcafe', 0)],
            model_name='HAL 9000',
            model_type=DeviceType.unknown,
            remarks="I'm sorry, Dave.",
        )
        self.deployment = Deployment(
            hostname='discovery.one',
            ip='127.0.0.1',
            mac='deadbeefcafe',
            device=device,
            preboot=None,
            venture=None,
            venture_role=None,
        )
        self.deployment.save()
        self.ip = IPAddress(address='127.0.0.1', device=device)
        self.ip.save()
        IPAddress(address='127.0.0.2', device=device).save()
        share_model = ComponentModel(type=ComponentType.share, name="share")
        share_model.save()
        share = DiskShare(wwn='x' * 33, device=device, model=share_model)
        share.save()
        DiskShareMount(share=share, device=device).save()
        OperatingSystem.create(os_name='GladOS',
                               dev=device,
                               family='',
                               priority=0)
        Software.create(dev=device,
                        model_name='soft',
                        path='/',
                        family='',
                        priority=0)

    def test_clean_plugin(self):
        clean(self.deployment.id)
        device = Device.objects.get(id=self.deployment.device.id)
        self.assertEqual(
            device.remarks,
            "-- Remarks below are for old role -/- from %s --\n"
            "I'm sorry, Dave." % datetime.date.today().strftime('%Y-%m-%d'),
        )
        self.assertEquals(device.ipaddress_set.count(), 1)
        self.assertEquals(device.ipaddress_set.all()[0].address, '127.0.0.1')
        self.assertFalse(device.diskshare_set.exists())
        self.assertFalse(device.disksharemount_set.exists())
        self.assertFalse(device.software_set.exists())
        self.assertFalse(device.operatingsystem_set.exists())
Beispiel #10
0
 def setUp(self):
     ip = IPAddress(address='127.0.0.1')
     ip.snmp_name = ('Hardware: EM64T Family 6 Model 15 Stepping 7 AT/AT '
                     'COMPATIBLE - Software: Windows Version 5.2 (Build '
                     '3790 Multiprocessor Free)')
     ip.snmp_community = 'public'
     ip.snmp_version = '2c'
     ip.save()
     self.ip = ip
     self.kwargs = {
         'ip': ip.address,
         'community': ip.snmp_community,
         'snmp_name': ip.snmp_name,
         'snmp_version': ip.snmp_version,
     }
Beispiel #11
0
 def setUp(self):
     ip = IPAddress(address='127.0.0.1')
     ip.snmp_name = ('Hardware: EM64T Family 6 Model 15 Stepping 7 AT/AT '
                     'COMPATIBLE - Software: Windows Version 5.2 (Build '
                     '3790 Multiprocessor Free)')
     ip.snmp_community = 'public'
     ip.snmp_version = '2c'
     ip.save()
     self.ip = ip
     self.kwargs = {
         'ip': ip.address,
         'community': ip.snmp_community,
         'snmp_name': ip.snmp_name,
         'snmp_version': ip.snmp_version,
     }
Beispiel #12
0
 def setUp(self):
     ip = IPAddress(address="127.0.0.1")
     ip.snmp_name = "IBM PowerPC CHRP Computer"
     ip.snmp_community = "public"
     ip.snmp_version = "2c"
     ip.save()
     self.ip = ip
     self.kwargs = {
         "ip": ip.address,
         "community": ip.snmp_community,
         "snmp_name": ip.snmp_name,
         "snmp_version": ip.snmp_version,
     }
     dev = Device.create(sn="foo", model_type=DeviceType.storage, model_name="foo")
     dev.save()
     self.share = DiskShare(wwn="2AC000250A9B5000", device=dev)
     self.share.save()
Beispiel #13
0
class CleanPluginTest(TestCase):

    def setUp(self):
        device = Device.create(
            ethernets=[('', 'deadbeefcafe', 0)],
            model_name='HAL 9000',
            model_type=DeviceType.unknown,
            remarks="I'm sorry, Dave.",
        )
        self.deployment = Deployment(
            hostname='discovery.one',
            ip='127.0.0.1',
            mac='deadbeefcafe',
            device=device,
            preboot=None,
            venture=None,
            venture_role=None,
        )
        self.deployment.save()
        self.ip = IPAddress(address='127.0.0.1', device=device)
        self.ip.save()
        IPAddress(address='127.0.0.2', device=device).save()
        share_model = ComponentModel(type=ComponentType.share, name="share")
        share_model.save()
        share = DiskShare(wwn='x' * 33, device=device, model=share_model)
        share.save()
        DiskShareMount(share=share, device=device).save()
        OperatingSystem.create(os_name='GladOS', dev=device, family='',
                               priority=0)
        Software.create(dev=device, model_name='soft', path='/', family='',
                        priority=0)

    def test_clean_plugin(self):
        clean(self.deployment.id)
        device = Device.objects.get(id=self.deployment.device.id)
        self.assertEqual(
            device.remarks,
            "-- Remarks below are for old role -/- from %s --\n"
            "I'm sorry, Dave." % datetime.date.today().strftime('%Y-%m-%d'),
        )
        self.assertEquals(device.ipaddress_set.count(), 1)
        self.assertEquals(device.ipaddress_set.all()[0].address, '127.0.0.1')
        self.assertFalse(device.diskshare_set.exists())
        self.assertFalse(device.disksharemount_set.exists())
        self.assertFalse(device.software_set.exists())
        self.assertFalse(device.operatingsystem_set.exists())
Beispiel #14
0
def _ip_create_record(form, request, device):
    hostname = form.cleaned_data.get('ip_new_hostname')
    address = form.cleaned_data.get('ip_new_address')
    if hostname and address:
        if IPAddress.objects.filter(address=address).exists():
            messages.error(
                request,
                "An IP address entry for %s already exists."
                % address
            )
            return
        record = IPAddress(address=address, hostname=hostname,
                           device=device)
        record.save()
        messages.success(request,
                         "An IP address entry for %s created." %
                         address)
Beispiel #15
0
 def setUp(self):
     ip = IPAddress(address='127.0.0.1')
     ip.snmp_name = 'IBM PowerPC CHRP Computer'
     ip.snmp_community = 'public'
     ip.snmp_version = '2c'
     ip.save()
     self.ip = ip
     self.kwargs = {
         'ip': ip.address,
         'community': ip.snmp_community,
         'snmp_name': ip.snmp_name,
         'snmp_version': ip.snmp_version,
     }
     dev = Device.create(sn='foo', model_type=DeviceType.storage,
                         model_name='foo')
     dev.save()
     self.share = DiskShare(wwn='2AC000250A9B5000', device=dev)
     self.share.save()
Beispiel #16
0
 def setUp(self):
     ip = IPAddress(address='127.0.0.1')
     ip.snmp_name = 'IBM PowerPC CHRP Computer'
     ip.snmp_community = 'public'
     ip.snmp_version = '2c'
     ip.save()
     self.ip = ip
     self.kwargs = {
         'ip': ip.address,
         'community': ip.snmp_community,
         'snmp_name': ip.snmp_name,
         'snmp_version': ip.snmp_version,
     }
     dev = Device.create(sn='foo', model_type=DeviceType.storage,
                         model_name='foo')
     dev.save()
     self.share = DiskShare(wwn='2AC000250A9B5000', device=dev)
     self.share.save()
Beispiel #17
0
 def test_validate_ip_owner(self):
     _validate_ip_owner('127.0.0.1', 'deadbeefcafe', 0)
     another_device = Device.create(
         ethernets=[('', 'deadbeefcafd', 0)],
         model_name='splat',
         model_type=DeviceType.unknown,
     )
     ip = IPAddress(address='127.0.0.1')
     ip.save()
     with self.assertRaises(forms.ValidationError):
         _validate_ip_owner('127.0.0.1', 'deadbeefcafe', 0)
     ip.device = Device.create(
         ethernets=[('', 'deadbeefcafe', 0)],
         model_name='splat',
         model_type=DeviceType.unknown,
     )
     ip.device.save()
     ip.save()
     _validate_ip_owner('127.0.0.1', 'deadbeefcafe', 0)
     ip.device = another_device
     ip.save()
     with self.assertRaises(forms.ValidationError):
         _validate_ip_owner('127.0.0.1', 'deadbeefcafe', 0)
 def test_validate_ip_owner(self):
     _validate_ip_owner('127.0.0.1', 'deadbeefcafe', 0)
     another_device = Device.create(
         ethernets=[('', 'deadbeefcafd', 0)],
         model_name='splat',
         model_type=DeviceType.unknown,
     )
     ip = IPAddress(address='127.0.0.1')
     ip.save()
     with self.assertRaises(forms.ValidationError):
         _validate_ip_owner('127.0.0.1', 'deadbeefcafe', 0)
     ip.device = Device.create(
         ethernets=[('', 'deadbeefcafe', 0)],
         model_name='splat',
         model_type=DeviceType.unknown,
     )
     ip.device.save()
     ip.save()
     _validate_ip_owner('127.0.0.1', 'deadbeefcafe', 0)
     ip.device = another_device
     ip.save()
     with self.assertRaises(forms.ValidationError):
         _validate_ip_owner('127.0.0.1', 'deadbeefcafe', 0)
class ModelsNetworkTest(TestCase):
    def setUp(self):
        self.dc = DataCenter(name="test_dc")
        self.dc.save()
        self.net1 = Network(
            name="test1",
            data_center=self.dc,
            address="192.168.0.1/16",
        )
        self.net1.save()
        self.net2 = Network(
            name="test2",
            data_center=self.dc,
            address="192.168.0.1/17",
        )
        self.net2.save()
        self.net3 = Network(
            name="test3",
            data_center=self.dc,
            address="192.168.128.1/17",
            reserved=5,
            reserved_top_margin=5,
        )
        self.net3.save()
        self.net4 = Network(
            name="test4",
            data_center=self.dc,
            address="192.168.133.1/24",
        )
        self.net4.save()
        self.net5 = Network(
            name="test5",
            data_center=self.dc,
            address="192.169.133.1/24",
        )
        self.net5.save()

        self.ip1 = IPAddress(address="192.168.128.10")
        self.ip1.save()
        self.ip2 = IPAddress(address="192.168.133.10")
        self.ip2.save()
        self.ip3 = IPAddress(address="192.168.128.11")
        self.ip3.save()

    def test_get_netmask(self):
        self.assertEquals(self.net1.get_netmask(), 16)
        self.assertEquals(self.net2.get_netmask(), 17)

    def test_get_subnetworks(self):
        res = self.net1.get_subnetworks()
        correct = [self.net2, self.net3]
        self.assertEquals(res, correct)

        res = self.net3.get_subnetworks()
        correct = [self.net4]
        self.assertEquals(res, correct)

    def test_get_address_summary(self):
        ret = self.net3.get_total_ips()
        self.assertEquals(ret, 32767)
        ret = self.net3.get_free_ips()
        self.assertEquals(ret, 32500)
        ret = self.net3.get_ip_usage_range()
        correct_range = [self.ip1, self.ip3, self.net4]
        self.assertEquals(ret, correct_range)

    def test_get_ip_usage_aggegated(self):
        ret = self.net3.get_ip_usage_aggegated()
        correct = [
            {
                'amount': 10,
                'range_end': '192.168.128.9',
                'range_start': '192.168.128.0',
                'type': 'free',
            },
            {
                'amount': 2,
                'range_end': '192.168.128.11',
                'range_start': '192.168.128.10',
                'type': 'addr',
            },
            {
                'amount': 1268,
                'range_end': '192.168.132.255',
                'range_start': '192.168.128.12',
                'type': 'free',
            },
            {
                'amount': 256,
                'range_end': '192.168.133.255',
                'range_start': '192.168.133.0',
                'type': self.net4,
            },
            {
                'amount': 31232,
                'range_end': '192.168.255.255',
                'range_start': '192.168.134.0',
                'type': 'free',
            },
        ]
        self.assertEquals(ret, correct)

    def test_get_network_tree(self):
        res = get_network_tree()
        correct = [{
            'network':
            self.net1,
            'subnetworks': [
                {
                    'network': self.net2,
                    'subnetworks': [],
                },
                {
                    'network': self.net3,
                    'subnetworks': [{
                        'network': self.net4,
                        'subnetworks': [],
                    }]
                },
            ]
        }, {
            'network': self.net5,
            'subnetworks': [],
        }]
        self.assertEquals(res, correct)

    def test_ip_is_public_or_no(self):
        ip_list = [
            ('92.143.123.123', True),
            ('10.168.123.123', False),
        ]
        for ip, is_public in ip_list:
            new_ip_address = IPAddress(address=ip)
            new_ip_address.save()
            self.assertEquals(new_ip_address.is_public, is_public)
Beispiel #20
0
class ModelsNetworkTest(TestCase):

    def setUp(self):
        self.dc = DataCenter(name="test_dc")
        self.dc.save()
        self.net1 = Network(
            name="test1",
            data_center=self.dc,
            address="192.168.0.1/16",
        )
        self.net1.save()
        self.net2 = Network(
            name="test2",
            data_center=self.dc,
            address="192.168.0.1/17",
        )
        self.net2.save()
        self.net3 = Network(
            name="test3",
            data_center=self.dc,
            address="192.168.128.1/17",
            reserved=5,
            reserved_top_margin=5,
        )
        self.net3.save()
        self.net4 = Network(
            name="test4",
            data_center=self.dc,
            address="192.168.133.1/24",
        )
        self.net4.save()
        self.net5 = Network(
            name="test5",
            data_center=self.dc,
            address="192.169.133.1/24",
        )
        self.net5.save()

        self.ip1 = IPAddress(address="192.168.128.10")
        self.ip1.save()
        self.ip2 = IPAddress(address="192.168.133.10")
        self.ip2.save()
        self.ip3 = IPAddress(address="192.168.128.11")
        self.ip3.save()

    def test_get_netmask(self):
        self.assertEquals(self.net1.get_netmask(), 16)
        self.assertEquals(self.net2.get_netmask(), 17)

    def test_get_subnetworks(self):
        res = self.net1.get_subnetworks()
        correct = [self.net2, self.net3]
        self.assertEquals(res, correct)

        res = self.net3.get_subnetworks()
        correct = [self.net4]
        self.assertEquals(res, correct)

    def test_get_address_summary(self):
        ret = self.net3.get_total_ips()
        self.assertEquals(ret, 32767)
        ret = self.net3.get_free_ips()
        self.assertEquals(ret, 32500)
        ret = self.net3.get_ip_usage_range()
        correct_range = [self.ip1, self.ip3, self.net4]
        self.assertEquals(ret, correct_range)

    def test_get_ip_usage_aggegated(self):
        ret = self.net3.get_ip_usage_aggegated()
        correct = [
            {
                'amount': 10,
                'range_end': '192.168.128.9',
                'range_start': '192.168.128.0',
                'type': 'free',
            },
            {
                'amount': 2,
                'range_end': '192.168.128.11',
                'range_start': '192.168.128.10',
                'type': 'addr',
            },
            {
                'amount': 1268,
                'range_end': '192.168.132.255',
                'range_start': '192.168.128.12',
                'type': 'free',
            },
            {
                'amount': 256,
                'range_end': '192.168.133.255',
                'range_start': '192.168.133.0',
                'type': self.net4,
            },
            {
                'amount': 31232,
                'range_end': '192.168.255.255',
                'range_start': '192.168.134.0',
                'type': 'free',
            },
        ]
        self.assertEquals(ret, correct)

    def test_get_network_tree(self):
        res = get_network_tree()
        correct = [
            {
                'network': self.net1,
                'subnetworks': [
                    {
                        'network': self.net2,
                        'subnetworks': [],
                    },
                    {
                        'network': self.net3,
                        'subnetworks': [
                            {
                                'network': self.net4,
                                'subnetworks': [],
                            }
                        ]
                    },
                ]
            },
            {
                'network': self.net5,
                'subnetworks': [],
            }
        ]
        self.assertEquals(res, correct)

    def test_ip_is_public_or_no(self):
        ip_list = [
            ('92.143.123.123', True),
            ('10.168.123.123', False),
        ]
        for ip, is_public in ip_list:
            new_ip_address = IPAddress(address=ip)
            new_ip_address.save()
            self.assertEquals(new_ip_address.is_public, is_public)