Пример #1
0
 def test_allows_setting_testing_scripts_to_none(self):
     node = factory.make_Node(status=NODE_STATUS.READY,
                              power_state=POWER_STATE.OFF)
     mock_start_commissioning = self.patch_autospec(node,
                                                    "start_commissioning")
     user = factory.make_admin()
     form = CommissionForm(instance=node,
                           user=user,
                           data={"testing_scripts": "none"})
     self.assertTrue(form.is_valid(), form.errors)
     node = form.save()
     self.assertIsNotNone(node)
     self.assertThat(
         mock_start_commissioning,
         MockCalledOnceWith(
             user,
             enable_ssh=False,
             skip_bmc_config=False,
             skip_networking=False,
             skip_storage=False,
             commissioning_scripts=[],
             testing_scripts=["none"],
             script_input={},
         ),
     )
Пример #2
0
 def test_class_start_commissioning_with_runtime_param_errors(self):
     node = factory.make_Node(status=NODE_STATUS.READY)
     user = factory.make_admin()
     commissioning_script = factory.make_Script(
         script_type=SCRIPT_TYPE.COMMISSIONING,
         parameters={"runtime": {
             "type": "runtime"
         }},
     )
     testing_script = factory.make_Script(
         script_type=SCRIPT_TYPE.TESTING,
         parameters={"runtime": {
             "type": "runtime"
         }},
     )
     self.patch_autospec(node, "start_commissioning")
     form = CommissionForm(
         instance=node,
         user=user,
         data={
             "commissioning_scripts": commissioning_script.name,
             "testing_scripts": testing_script.name,
             "%s_runtime" % commissioning_script.name:
             factory.make_name("bad"),
             "%s_runtime" % testing_script.name: factory.make_name("bad"),
         },
     )
     self.assertFalse(form.is_valid())
Пример #3
0
 def test_calls_start_commissioning_if_already_on(self):
     node = factory.make_Node(
         status=NODE_STATUS.READY,
         power_state=POWER_STATE.ON,
         interface=True,
     )
     user = factory.make_admin()
     mock_start_commissioning = self.patch_autospec(node,
                                                    "start_commissioning")
     form = CommissionForm(instance=node, user=user, data={})
     self.assertTrue(form.is_valid(), form.errors)
     node = form.save()
     self.assertThat(
         mock_start_commissioning,
         MockCalledOnceWith(
             user,
             enable_ssh=False,
             skip_bmc_config=False,
             skip_networking=False,
             skip_storage=False,
             commissioning_scripts=[],
             testing_scripts=[],
             script_input={},
         ),
     )
Пример #4
0
 def test__class_start_commissioning_with_runtime_param_errors(self):
     node = factory.make_Node(status=NODE_STATUS.READY)
     user = factory.make_admin()
     commissioning_script = factory.make_Script(
         script_type=SCRIPT_TYPE.COMMISSIONING,
         parameters={
             'runtime': {
                 'type': 'runtime'
             },
         })
     testing_script = factory.make_Script(script_type=SCRIPT_TYPE.TESTING,
                                          parameters={
                                              'runtime': {
                                                  'type': 'runtime'
                                              },
                                          })
     self.patch_autospec(node, 'start_commissioning')
     form = CommissionForm(instance=node,
                           user=user,
                           data={
                               'commissioning_scripts':
                               commissioning_script.name,
                               'testing_scripts':
                               testing_script.name,
                               '%s_runtime' % commissioning_script.name:
                               factory.make_name('bad'),
                               '%s_runtime' % testing_script.name:
                               factory.make_name('bad'),
                           })
     self.assertFalse(form.is_valid())
Пример #5
0
 def test__class_start_commissioning_with_interface_param(self):
     node = factory.make_Node(status=NODE_STATUS.READY, interface=False)
     commissioning_interface = factory.make_Interface(node=node)
     testing_interface = factory.make_Interface(node=node)
     user = factory.make_admin()
     commissioning_script = factory.make_Script(
         script_type=SCRIPT_TYPE.COMMISSIONING,
         parameters={
             'interface': {
                 'type': 'interface'
             },
         })
     testing_script = factory.make_Script(script_type=SCRIPT_TYPE.TESTING,
                                          parameters={
                                              'interface': {
                                                  'type': 'interface'
                                              },
                                          })
     mock_start_commissioning = self.patch_autospec(node,
                                                    'start_commissioning')
     commissioning_input = random.choice([
         str(commissioning_interface.id), commissioning_interface.name,
         str(commissioning_interface.mac_address),
         commissioning_interface.vendor, commissioning_interface.product,
         '%s:%s' %
         (commissioning_interface.vendor, commissioning_interface.product)
     ] + commissioning_interface.tags)
     testing_input = random.choice([
         str(testing_interface.id), testing_interface.name,
         str(testing_interface.mac_address), testing_interface.vendor,
         testing_interface.product,
         '%s:%s' % (testing_interface.vendor, testing_interface.product)
     ] + testing_interface.tags)
     form = CommissionForm(instance=node,
                           user=user,
                           data={
                               'commissioning_scripts':
                               commissioning_script.name,
                               'testing_scripts':
                               testing_script.name,
                               '%s_interface' % commissioning_script.name:
                               commissioning_input,
                               '%s_interface' % testing_script.name:
                               testing_input,
                           })
     self.assertTrue(form.is_valid(), form.errors)
     node = form.save()
     self.assertIsNotNone(node)
     self.assertThat(
         mock_start_commissioning,
         MockCalledOnceWith(
             user, False, False, False, False, [commissioning_script.name],
             [testing_script.name], {
                 commissioning_script.name: {
                     'interface': commissioning_input,
                 },
                 testing_script.name: {
                     'interface': testing_input,
                 },
             }))
Пример #6
0
 def test__class_start_commissioning_with_storage_param(self):
     node = factory.make_Node(status=NODE_STATUS.READY,
                              with_boot_disk=False)
     commissioning_bd = factory.make_PhysicalBlockDevice(node=node)
     testing_bd = factory.make_PhysicalBlockDevice(node=node)
     user = factory.make_admin()
     commissioning_script = factory.make_Script(
         script_type=SCRIPT_TYPE.COMMISSIONING,
         parameters={
             'storage': {
                 'type': 'storage'
             },
         })
     testing_script = factory.make_Script(script_type=SCRIPT_TYPE.TESTING,
                                          parameters={
                                              'storage': {
                                                  'type': 'storage'
                                              },
                                          })
     mock_start_commissioning = self.patch_autospec(node,
                                                    'start_commissioning')
     commissioning_input = random.choice([
         str(commissioning_bd.id), commissioning_bd.name,
         commissioning_bd.model, commissioning_bd.serial,
         '%s:%s' % (commissioning_bd.model, commissioning_bd.serial)
     ] + commissioning_bd.tags)
     testing_input = random.choice([
         str(testing_bd.id), testing_bd.name, testing_bd.model,
         testing_bd.serial,
         '%s:%s' % (testing_bd.model, testing_bd.serial)
     ] + testing_bd.tags)
     form = CommissionForm(instance=node,
                           user=user,
                           data={
                               'commissioning_scripts':
                               commissioning_script.name,
                               'testing_scripts':
                               testing_script.name,
                               '%s_storage' % commissioning_script.name:
                               commissioning_input,
                               '%s_storage' % testing_script.name:
                               testing_input,
                           })
     self.assertTrue(form.is_valid(), form.errors)
     node = form.save()
     self.assertIsNotNone(node)
     self.assertThat(
         mock_start_commissioning,
         MockCalledOnceWith(
             user, False, False, False, False, [commissioning_script.name],
             [testing_script.name], {
                 commissioning_script.name: {
                     'storage': commissioning_input,
                 },
                 testing_script.name: {
                     'storage': testing_input,
                 },
             }))
Пример #7
0
 def test_doesnt_require_anything(self):
     node = factory.make_Node(
         status=NODE_STATUS.READY,
         power_state=POWER_STATE.OFF,
         interface=True,
     )
     user = factory.make_admin()
     form = CommissionForm(instance=node, user=user, data={})
     self.assertTrue(form.is_valid(), form.errors)
Пример #8
0
 def test_validates_testing_scripts(self):
     node = factory.make_Node(status=NODE_STATUS.READY,
                              power_state=POWER_STATE.OFF)
     user = factory.make_admin()
     form = CommissionForm(
         instance=node,
         user=user,
         data={"testing_scripts": factory.make_name("script")},
     )
     self.assertFalse(form.is_valid())
Пример #9
0
 def test_class_start_commissioning_with_url_param(self):
     node = factory.make_Node(status=NODE_STATUS.READY)
     user = factory.make_admin()
     commissioning_script = factory.make_Script(
         script_type=SCRIPT_TYPE.COMMISSIONING,
         parameters={"url": {
             "type": "url"
         }},
     )
     testing_script = factory.make_Script(
         script_type=SCRIPT_TYPE.TESTING,
         parameters={"url": {
             "type": "url"
         }},
     )
     mock_start_commissioning = self.patch_autospec(node,
                                                    "start_commissioning")
     commissioning_input = factory.make_url(scheme="http")
     testing_input = factory.make_url(scheme="http")
     form = CommissionForm(
         instance=node,
         user=user,
         data={
             "commissioning_scripts": commissioning_script.name,
             "testing_scripts": testing_script.name,
             "%s_url" % commissioning_script.name: commissioning_input,
             "%s_url" % testing_script.name: testing_input,
         },
     )
     self.assertTrue(form.is_valid(), form.errors)
     node = form.save()
     self.assertIsNotNone(node)
     self.assertThat(
         mock_start_commissioning,
         MockCalledOnceWith(
             user,
             False,
             False,
             False,
             False,
             [commissioning_script.name],
             [testing_script.name],
             {
                 commissioning_script.name: {
                     "url": commissioning_input
                 },
                 testing_script.name: {
                     "url": testing_input
                 },
             },
         ),
     )
Пример #10
0
 def test_class_start_commissioning_with_runtime_param(self):
     node = factory.make_Node(status=NODE_STATUS.READY, interface=True)
     user = factory.make_admin()
     commissioning_script = factory.make_Script(
         script_type=SCRIPT_TYPE.COMMISSIONING,
         parameters={"runtime": {
             "type": "runtime"
         }},
     )
     testing_script = factory.make_Script(
         script_type=SCRIPT_TYPE.TESTING,
         parameters={"runtime": {
             "type": "runtime"
         }},
     )
     mock_start_commissioning = self.patch_autospec(node,
                                                    "start_commissioning")
     commissioning_input = random.choice(["168:00:00", "10080:00", 604800])
     testing_input = random.choice(["168:00:00", "10080:00", 604800])
     form = CommissionForm(
         instance=node,
         user=user,
         data={
             "commissioning_scripts": commissioning_script.name,
             "testing_scripts": testing_script.name,
             "%s_runtime" % commissioning_script.name: commissioning_input,
             "%s_runtime" % testing_script.name: testing_input,
         },
     )
     self.assertTrue(form.is_valid(), form.errors)
     node = form.save()
     self.assertIsNotNone(node)
     self.assertThat(
         mock_start_commissioning,
         MockCalledOnceWith(
             user,
             False,
             False,
             False,
             False,
             [commissioning_script.name],
             [testing_script.name],
             {
                 commissioning_script.name: {
                     "runtime": 604800
                 },
                 testing_script.name: {
                     "runtime": 604800
                 },
             },
         ),
     )
Пример #11
0
 def test__not_allowed_in_bad_state(self):
     node = factory.make_Node(status=NODE_STATUS.DEPLOYING,
                              power_state=POWER_STATE.OFF)
     user = factory.make_admin()
     form = CommissionForm(instance=node, user=user, data={})
     self.assertFalse(form.is_valid(), form.errors)
     self.assertEqual(
         {
             '__all__': [
                 "Commission is not available because of the current state "
                 "of the node."
             ],
         }, form.errors)
Пример #12
0
 def test__class_start_commissioning_with_runtime_param(self):
     node = factory.make_Node(status=NODE_STATUS.READY)
     user = factory.make_admin()
     commissioning_script = factory.make_Script(
         script_type=SCRIPT_TYPE.COMMISSIONING,
         parameters={
             'runtime': {
                 'type': 'runtime'
             },
         })
     testing_script = factory.make_Script(script_type=SCRIPT_TYPE.TESTING,
                                          parameters={
                                              'runtime': {
                                                  'type': 'runtime'
                                              },
                                          })
     mock_start_commissioning = self.patch_autospec(node,
                                                    'start_commissioning')
     commissioning_input = random.choice(['168:00:00', '10080:00', 604800])
     testing_input = random.choice(['168:00:00', '10080:00', 604800])
     form = CommissionForm(instance=node,
                           user=user,
                           data={
                               'commissioning_scripts':
                               commissioning_script.name,
                               'testing_scripts':
                               testing_script.name,
                               '%s_runtime' % commissioning_script.name:
                               commissioning_input,
                               '%s_runtime' % testing_script.name:
                               testing_input,
                           })
     self.assertTrue(form.is_valid(), form.errors)
     node = form.save()
     self.assertIsNotNone(node)
     self.assertThat(
         mock_start_commissioning,
         MockCalledOnceWith(
             user, False, False, False, False, [commissioning_script.name],
             [testing_script.name], {
                 commissioning_script.name: {
                     'runtime': 604800
                 },
                 testing_script.name: {
                     'runtime': 604800
                 },
             }))
Пример #13
0
 def test_calls_start_commissioning_with_options(self):
     node = factory.make_Node(
         status=NODE_STATUS.READY,
         power_state=POWER_STATE.OFF,
         interface=True,
     )
     user = factory.make_admin()
     commissioning_scripts = [
         factory.make_Script(script_type=SCRIPT_TYPE.COMMISSIONING).name
         for _ in range(3)
     ]
     testing_scripts = [
         factory.make_Script(script_type=SCRIPT_TYPE.TESTING).name
         for _ in range(3)
     ]
     mock_start_commissioning = self.patch_autospec(node,
                                                    "start_commissioning")
     form = CommissionForm(
         instance=node,
         user=user,
         data={
             "enable_ssh": True,
             "skip_bmc_config": True,
             "skip_networking": True,
             "skip_storage": True,
             "commissioning_scripts": ",".join(commissioning_scripts),
             "testing_scripts": ",".join(testing_scripts),
         },
     )
     self.assertTrue(form.is_valid(), form.errors)
     node = form.save()
     self.assertIsNotNone(node)
     self.assertThat(
         mock_start_commissioning,
         MockCalledOnceWith(
             user,
             enable_ssh=True,
             skip_bmc_config=True,
             skip_networking=True,
             skip_storage=True,
             commissioning_scripts=commissioning_scripts,
             testing_scripts=testing_scripts,
             script_input={},
         ),
     )
Пример #14
0
 def test_class_start_commissioning_can_override_global_param(self):
     node = factory.make_Node(status=NODE_STATUS.READY)
     commissioning_bd = factory.make_PhysicalBlockDevice(node=node)
     testing_bd = factory.make_PhysicalBlockDevice(node=node)
     user = factory.make_admin()
     global_commissioning_script = factory.make_Script(
         script_type=SCRIPT_TYPE.COMMISSIONING,
         parameters={"storage": {
             "type": "storage"
         }},
     )
     commissioning_script = factory.make_Script(
         script_type=SCRIPT_TYPE.COMMISSIONING,
         parameters={"storage": {
             "type": "storage"
         }},
     )
     global_testing_script = factory.make_Script(
         script_type=SCRIPT_TYPE.TESTING,
         parameters={"storage": {
             "type": "storage"
         }},
     )
     testing_script = factory.make_Script(
         script_type=SCRIPT_TYPE.TESTING,
         parameters={"storage": {
             "type": "storage"
         }},
     )
     mock_start_commissioning = self.patch_autospec(node,
                                                    "start_commissioning")
     commissioning_input = random.choice([
         str(commissioning_bd.id),
         commissioning_bd.name,
         commissioning_bd.model,
         commissioning_bd.serial,
         "%s:%s" % (commissioning_bd.model, commissioning_bd.serial),
     ] + commissioning_bd.tags)
     testing_input = random.choice([
         str(testing_bd.id),
         testing_bd.name,
         testing_bd.model,
         testing_bd.serial,
         "%s:%s" % (testing_bd.model, testing_bd.serial),
     ] + testing_bd.tags)
     form = CommissionForm(
         instance=node,
         user=user,
         data={
             "commissioning_scripts":
             "%s,%s" % (
                 global_commissioning_script.name,
                 commissioning_script.name,
             ),
             "testing_scripts":
             "%s,%s" % (global_testing_script.name, testing_script.name),
             "storage":
             "all",
             "%s_storage" % commissioning_script.name:
             commissioning_input,
             "%s_storage" % testing_script.name:
             testing_input,
         },
     )
     self.assertTrue(form.is_valid(), form.errors)
     node = form.save()
     self.assertIsNotNone(node)
     self.assertThat(
         mock_start_commissioning,
         MockCalledOnceWith(
             user,
             False,
             False,
             False,
             False,
             [global_commissioning_script.name, commissioning_script.name],
             [global_testing_script.name, testing_script.name],
             {
                 global_commissioning_script.name: {
                     "storage": "all"
                 },
                 commissioning_script.name: {
                     "storage": commissioning_input
                 },
                 global_testing_script.name: {
                     "storage": "all"
                 },
                 testing_script.name: {
                     "storage": testing_input
                 },
             },
         ),
     )