Esempio n. 1
0
 def test_device_table_hidden(self):
     hidden = DeviceType(name="hidden", owners_only=True, health_check_job='')
     hidden.save()
     device = Device(device_type=hidden, hostname='hidden1', status=Device.OFFLINE)
     device.save()
     view = TestDeviceView(None)
     self.assertEqual(len(view.get_queryset()), 0)
Esempio n. 2
0
 def test_device_table_hidden(self):
     hidden = DeviceType(name="hidden", owners_only=True)
     hidden.save()  # pylint: disable=no-member
     device = Device(device_type=hidden, hostname='hidden1')
     device.save()  # pylint: disable=no-member
     view = TestDeviceView(None)
     self.assertEqual(len(view.get_queryset()), 0)
Esempio n. 3
0
 def test_device_table_view(self):
     device_type = DeviceType(name="generic", owners_only=False)
     device_type.save()  # pylint: disable=no-member
     device = Device(device_type=device_type, hostname='generic1')
     user = self.make_user()
     device.user = user
     device.save()  # pylint: disable=no-member
     view = TestDeviceView(None)
     self.assertEqual(len(view.get_queryset()), 1)
Esempio n. 4
0
 def test_device_table_view(self):
     device_type = DeviceType(name="generic", owners_only=False, health_check_job='')
     device_type.save()
     device = Device(device_type=device_type, hostname='generic1', status=Device.OFFLINE)
     user = self.make_user()
     device.user = user
     device.save()
     view = TestDeviceView(None)
     self.assertEqual(len(view.get_queryset()), 1)
Esempio n. 5
0
 def test_unknown_invalid_template(self):
     name = "nowhere-never-skip"
     dt = DeviceType(name=name)
     dt.save()
     dt.refresh_from_db()
     device = Device(device_type=dt, hostname='test-01', health=Device.HEALTH_GOOD)
     device.save()
     device.refresh_from_db()
     self.assertIsNotNone([d for d in Device.objects.filter(device_type=dt)])
     self.assertTrue(Device.CONFIG_PATH.startswith(self.basedir))
     found = False
     for device_file in os.listdir(self.types_dir):
         if device_file == '%s.jinja2' % name:
             self.fail("Configuration error - %s.jinja2 should NOT exist in %s" % (name, self.types_dir))
     self.assertIsNone(device.load_configuration())
     self.assertIsNotNone([device in Device.objects.filter(device_type=dt)])
     self.assertFalse(bool(load_devicetype_template(device.device_type.name)))
     self.assertTrue(invalid_template(device.device_type))
Esempio n. 6
0
 def test_juno_vexpress_valid_template(self):
     name = "juno-r2"
     dt = DeviceType(name=name)
     dt.save()
     dt.refresh_from_db()
     device = Device(device_type=dt, hostname='juno-r2-01', health=Device.HEALTH_GOOD)
     device.save()
     device.refresh_from_db()
     self.assertIsNotNone([d for d in Device.objects.filter(device_type=dt)])
     for device_file in os.listdir(self.types_dir):
         if device_file == 'juno-r2.jinja2':
             self.fail("Configuration error - %s.jinja2 should NOT exist in %s" % (name, self.types_dir))
     self.assertTrue(Device.CONFIG_PATH.startswith(self.basedir))
     self.assertEqual('juno-r2-01', device.hostname)
     self.assertIsNotNone(device.load_configuration())
     self.assertEqual([device], [device for device in Device.objects.filter(device_type=dt)])
     self.assertEqual('juno', device.get_extends())
     self.assertFalse(bool(load_devicetype_template(device.device_type.name)))
     self.assertFalse(invalid_template(device.device_type))
Esempio n. 7
0
 def test_access_while_hidden(self):
     hidden = DeviceType(name="hidden", owners_only=True, health_check_job='')
     device = Device(device_type=hidden, hostname='hidden1', status=Device.OFFLINE)
     user = self.factory.make_user()
     device.user = user
     device.save()
     self.assertEqual(device.is_public, False)
     self.assertEqual(device.user, user)
     user2 = self.factory.make_user()
     self.assertEqual(device.can_submit(user2), False)
     self.assertEqual(device.can_submit(user), True)
Esempio n. 8
0
    def test_put_into_looping_mode(self):
        foo = DeviceType(name='foo')
        device = Device(device_type=foo,
                        hostname='foo01',
                        status=Device.OFFLINE)
        device.save()

        device.put_into_looping_mode(None, None)

        self.assertEqual(device.status, Device.IDLE, "should be IDLE")
        self.assertEqual(device.health_status, Device.HEALTH_LOOPING,
                         "should be LOOPING")
 def test_access_retired_hidden(self):
     hidden = DeviceType(name="hidden", owners_only=True, health_check_job='')
     device = Device(device_type=hidden, hostname='hidden2', status=Device.RETIRED)
     user = self.factory.make_user()
     device.user = user
     device.save()
     self.assertEqual(device.is_public, False)
     self.assertEqual(device.user, user)
     user2 = self.factory.make_user()
     self.assertEqual(device.can_submit(user2), False)
     # user cannot submit as the device is retired
     self.assertEqual(device.can_submit(user), False)
Esempio n. 10
0
    def add(
        self,
        name,
        description,
        display,
        owners_only,
        health_frequency,
        health_denominator,
    ):
        """
        Name
        ----
        `scheduler.device_types.add` (`name`, `description`, `display`, `owners_only`, `health_frequency`, health_denominator`)

        Description
        -----------
        [superuser only]
        Add a new device-type to the database. Devices will need a suitable
        template to use the new device-type.

        Arguments
        ---------
        `name`: string
          Name of the device-type
        `description`: string
          Device-type description
        `display`: bool
          Is the device-type displayed in the GUI?
        `owners_only`: bool
          DEPRECATED: this field is not used any more
        `health_frequency`: int
          How often to run health checks
        `health_denominator`: string ("hours" or "jobs")
          Initiate health checks by hours or by jobs

        Return value
        ------------
        None
        """
        if health_denominator == "hours":
            health_denominator = DeviceType.HEALTH_PER_HOUR
        elif health_denominator == "jobs":
            health_denominator = DeviceType.HEALTH_PER_JOB
        else:
            raise xmlrpc.client.Fault(
                400, "Bad request: invalid health_denominator.")

        try:
            dt = DeviceType(
                name=name,
                description=description,
                display=display,
                health_frequency=health_frequency,
                health_denominator=health_denominator,
            )
            dt.full_clean()
            dt.save()
        except (IntegrityError, ValidationError):
            raise xmlrpc.client.Fault(
                400, "Bad request: device-type name is already used.")
Esempio n. 11
0
 def test_juno_vexpress_valid_template(self):
     name = "juno-r2"
     dt = DeviceType(name=name)
     dt.save()
     dt.refresh_from_db()
     device = Device(device_type=dt,
                     hostname="juno-r2-01",
                     health=Device.HEALTH_GOOD)
     device.save()
     device.refresh_from_db()
     self.assertIsNotNone(
         [d for d in Device.objects.filter(device_type=dt)])
     for device_file in os.listdir(settings.DEVICE_TYPES_PATH):
         if device_file == "juno-r2.jinja2":
             self.fail(
                 "Configuration error - %s.jinja2 should NOT exist in %s" %
                 (name, settings.DEVICE_TYPES_PATH))
     self.assertTrue(settings.DEVICES_PATH.startswith(self.basedir))
     self.assertEqual("juno-r2-01", device.hostname)
     self.assertIsNotNone(device.load_configuration())
     self.assertEqual(
         [device],
         [device for device in Device.objects.filter(device_type=dt)])
     self.assertEqual("juno", device.get_extends())
     self.assertFalse(
         bool(load_devicetype_template(device.device_type.name)))
     self.assertFalse(invalid_template(device.device_type))
Esempio n. 12
0
 def test_bbb_valid_template(self):
     name = "beaglebone-black"
     dt = DeviceType(name=name)
     dt.save()
     dt.refresh_from_db()
     device = Device(device_type=dt,
                     hostname="bbb-01",
                     health=Device.HEALTH_GOOD)
     device.save()
     device.refresh_from_db()
     self.assertIsNotNone(
         [d for d in Device.objects.filter(device_type=dt)])
     self.assertTrue(settings.DEVICES_PATH.startswith(self.basedir))
     found = False
     for device_file in os.listdir(settings.DEVICE_TYPES_PATH):
         if device_file == "%s.jinja2" % name:
             found = True
             break
     if not found:
         self.fail("Configuration error - %s.jinja2 should exist in %s" %
                   (name, settings.DEVICE_TYPES_PATH))
     self.assertIsNotNone([device in Device.objects.filter(device_type=dt)])
     self.assertIsNotNone(device.load_configuration())
     self.assertTrue(bool(load_devicetype_template(
         device.device_type.name)))
     self.assertFalse(invalid_template(device.device_type))
Esempio n. 13
0
 def test_access_while_private(self):
     hidden = DeviceType(name="hidden", owners_only=True)
     device = Device(device_type=hidden,
                     hostname="hidden1",
                     is_public=False)
     user = self.factory.make_user()
     device.user = user
     device.save()
     self.assertEqual(device.is_public, False)
     self.assertEqual(device.user, user)
     user2 = self.factory.make_user()
     self.assertEqual(device.can_submit(user2), False)
     self.assertEqual(device.can_submit(user), True)
Esempio n. 14
0
    def test_maintenance_mode(self):
        foo = DeviceType(name='foo')
        device = Device(device_type=foo, hostname='foo01', status=Device.IDLE)
        device.save()

        device.put_into_maintenance_mode(None, None)

        self.assertEqual(device.status, Device.OFFLINE, "should be offline")

        device.status = Device.RUNNING
        device.put_into_maintenance_mode(None, None)

        self.assertEqual(device.status, Device.OFFLINING,
                         "should be offlining")
Esempio n. 15
0
    def test_online_mode(self):
        foo = DeviceType(name='foo')
        device = Device(device_type=foo, hostname='foo02', status=Device.OFFLINE)
        device.save()
        device.put_into_online_mode(None, None)
        self.assertEqual(device.status, Device.IDLE, "should be idle")

        device.status = Device.OFFLINING
        device.put_into_online_mode(None, None)
        self.assertIsNone(device.current_job)
        self.assertEqual(device.status, Device.IDLE, "should be idle")

        device.status = Device.RETIRED
        device.put_into_online_mode(None, None)
        self.assertEqual(device.status, Device.RETIRED, "should be retired")
Esempio n. 16
0
 def test_unknown_invalid_template(self):
     name = "nowhere-never-skip"
     dt = DeviceType(name=name)
     dt.save()
     dt.refresh_from_db()
     device = Device(device_type=dt, hostname="test-01", health=Device.HEALTH_GOOD)
     device.save()
     device.refresh_from_db()
     self.assertIsNotNone([d for d in Device.objects.filter(device_type=dt)])
     self.assertIsNone(device.load_configuration())
     self.assertIsNotNone([device in Device.objects.filter(device_type=dt)])
     self.assertFalse(bool(load_devicetype_template(device.device_type.name)))
     self.assertTrue(invalid_template(device.device_type))
Esempio n. 17
0
    def test_create_logentry(self):
        foo = DeviceType(name='foo')
        device = Device(device_type=foo, hostname='foo01', status=Device.OFFLINE)
        device.save()

        # only unit tests should call these functions with None, None
        # if that is made a requirement of the device status functions, fix this test.
        device.put_into_looping_mode(None, None)
        self.assertEqual(device.status, Device.IDLE, "should be IDLE")
        self.assertEqual(device.health_status, Device.HEALTH_LOOPING, "should be LOOPING")
        device_ct = ContentType.objects.get_for_model(Device)
        self.assertEqual(0, len(LogEntry.objects.filter(content_type=device_ct, action_flag=2).order_by('-action_time')))

        user = self.factory.make_user()
        device.put_into_maintenance_mode(user, 'test_create_logentry')
        self.assertEqual(device.status, Device.OFFLINE, "should be OFFLINE")
        self.assertEqual(device.health_status, Device.HEALTH_UNKNOWN, "should be UNKNOWN")
        # the device state transition also creates a log entry
        self.assertEqual(2, len(LogEntry.objects.filter(content_type=device_ct, action_flag=2).order_by('-action_time')))
Esempio n. 18
0
 def test_bbb_valid_template(self):
     name = "beaglebone-black"
     dt = DeviceType(name=name)
     dt.save()
     dt.refresh_from_db()
     device = Device(device_type=dt, hostname="bbb-01", health=Device.HEALTH_GOOD)
     device.save()
     device.refresh_from_db()
     self.assertIsNotNone([d for d in Device.objects.filter(device_type=dt)])
     self.assertTrue(File("device-type").exists(f"{name}.jinja2"))
     self.assertIsNotNone([device in Device.objects.filter(device_type=dt)])
     self.assertIsNotNone(device.load_configuration())
     self.assertTrue(bool(load_devicetype_template(device.device_type.name)))
     self.assertFalse(invalid_template(device.device_type))
Esempio n. 19
0
 def test_retired_invalid_template(self):
     name = "beaglebone-black"
     dt = DeviceType(name=name)
     dt.save()
     dt.refresh_from_db()
     device = Device(device_type=dt, hostname="bbb-01", health=Device.HEALTH_RETIRED)
     device.save()
     device.refresh_from_db()
     self.assertEqual(
         [],
         list(
             Device.objects.filter(
                 Q(device_type=dt), ~Q(health=Device.HEALTH_RETIRED)
             )
         ),
     )
     self.assertIsNotNone([d for d in Device.objects.filter(device_type=dt)])
     self.assertFalse(invalid_template(device.device_type))
Esempio n. 20
0
 def test_juno_vexpress_valid_template(self):
     name = "juno-r2"
     dt = DeviceType(name=name)
     dt.save()
     dt.refresh_from_db()
     device = Device(
         device_type=dt, hostname="juno-r2-01", health=Device.HEALTH_GOOD
     )
     device.save()
     device.refresh_from_db()
     self.assertIsNotNone([d for d in Device.objects.filter(device_type=dt)])
     self.assertFalse(File("device-type").exists("juno-r2.jinja2"))
     self.assertEqual("juno-r2-01", device.hostname)
     self.assertIsNotNone(device.load_configuration())
     self.assertEqual(
         [device], [device for device in Device.objects.filter(device_type=dt)]
     )
     self.assertEqual("juno", device.get_extends())
     self.assertFalse(bool(load_devicetype_template(device.device_type.name)))
     self.assertFalse(invalid_template(device.device_type))
Esempio n. 21
0
 def test_unknown_invalid_template(self):
     name = "nowhere-never-skip"
     dt = DeviceType(name=name)
     dt.save()
     dt.refresh_from_db()
     device = Device(device_type=dt,
                     hostname="test-01",
                     health=Device.HEALTH_GOOD)
     device.save()
     device.refresh_from_db()
     self.assertIsNotNone(
         [d for d in Device.objects.filter(device_type=dt)])
     self.assertTrue(Device.CONFIG_PATH.startswith(self.basedir))
     found = False
     for device_file in os.listdir(self.types_dir):
         if device_file == "%s.jinja2" % name:
             self.fail(
                 "Configuration error - %s.jinja2 should NOT exist in %s" %
                 (name, self.types_dir))
     self.assertIsNone(device.load_configuration())
     self.assertIsNotNone([device in Device.objects.filter(device_type=dt)])
     self.assertFalse(
         bool(load_devicetype_template(device.device_type.name)))
     self.assertTrue(invalid_template(device.device_type))
Esempio n. 22
0
    def test_active_device_types(self):
        name = "beaglebone-black"
        dt = DeviceType(name=name)
        dt.save()
        dt.refresh_from_db()
        device = Device(device_type=dt, hostname="bbb-01", health=Device.HEALTH_GOOD)
        device.save()
        device = Device(device_type=dt, hostname="bbb-02", health=Device.HEALTH_RETIRED)
        device.save()

        name = "juno-r2"
        dt = DeviceType(name=name)
        dt.save()
        dt.refresh_from_db()
        device = Device(
            device_type=dt, hostname="juno-r2-01", health=Device.HEALTH_RETIRED
        )
        device.save()

        name = "juno"
        dt = DeviceType(name=name)
        dt.display = False
        dt.save()
        dt.refresh_from_db()
        dt.refresh_from_db()
        device = Device(
            device_type=dt, hostname="juno-01", health=Device.HEALTH_UNKNOWN
        )
        device.save()

        name = "qemu"
        dt = DeviceType(name=name)
        dt.save()
        dt.refresh_from_db()
        device = Device(device_type=dt, hostname="qemu-01", health=Device.HEALTH_GOOD)
        device.save()

        self.assertEqual(
            {"bbb-01", "bbb-02", "juno-r2-01", "qemu-01", "juno-01"},
            set(Device.objects.all().values_list("hostname", flat=True)),
        )

        self.assertEqual(
            {"beaglebone-black", "juno", "juno-r2", "qemu"},
            set(DeviceType.objects.values_list("name", flat=True)),
        )

        # exclude juno-r2 because all devices of that device-type are retired.
        # exclude juno because the device_type is set to not be displayed.
        # include beaglebone-black because not all devices of that type are retired.
        # include qemu because none of the devices of that type are retired.
        self.assertEqual(
            {"beaglebone-black", "qemu"},
            set(active_device_types().values_list("name", flat=True)),
        )