Exemplo n.º 1
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))
Exemplo n.º 2
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))
Exemplo n.º 3
0
def deploy_methods(device_type, methods):
    data = load_devicetype_template(device_type)
    if not data or "actions" not in data or methods not in data["actions"]:
        return []
    methods = data["actions"][methods]["methods"]
    if isinstance(methods, dict):
        return methods.keys()
    return [methods]
Exemplo n.º 4
0
def deploy_methods(device_type, methods):
    data = load_devicetype_template(device_type)
    if not data or 'actions' not in data or methods not in data['actions']:
        return None
    methods = data['actions'][methods]['methods']
    if isinstance(methods, dict):
        return methods.keys()
    return [methods]
Exemplo n.º 5
0
def deploy_methods(device_type, methods):
    data = load_devicetype_template(device_type)
    if not data or 'actions' not in data or methods not in data['actions']:
        return []
    methods = data['actions'][methods]['methods']
    if isinstance(methods, dict):
        return methods.keys()
    return [methods]
Exemplo n.º 6
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))
Exemplo n.º 7
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))
Exemplo n.º 8
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))
Exemplo n.º 9
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))
Exemplo n.º 10
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))
Exemplo n.º 11
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))
Exemplo n.º 12
0
def device_type_timeouts(device_type):
    data = load_devicetype_template(device_type)
    if not data or "timeouts" not in data:
        return None
    return data["timeouts"]
Exemplo n.º 13
0
 def test_device_type_parser(self):
     data = load_devicetype_template("beaglebone-black")
     self.assertIsNotNone(data)
     self.assertIn("actions", data)
     self.assertIn("deploy", data["actions"])
     self.assertIn("boot", data["actions"])
Exemplo n.º 14
0
 def test_device_type_parser(self):
     data = load_devicetype_template('beaglebone-black')
     self.assertIsNotNone(data)
     self.assertIn('actions', data)
     self.assertIn('deploy', data['actions'])
     self.assertIn('boot', data['actions'])
Exemplo n.º 15
0
 def test_device_type_parser(self):
     data = load_devicetype_template('beaglebone-black')
     self.assertIsNotNone(data)
     self.assertIn('actions', data)
     self.assertIn('deploy', data['actions'])
     self.assertIn('boot', data['actions'])
Exemplo n.º 16
0
def device_type_timeouts(device_type):
    data = load_devicetype_template(device_type)
    if not data or 'timeouts' not in data:
        return None
    return data['timeouts']