def test_Deploy_allocates_node_if_node_not_already_allocated(self): user = factory.make_User() node = factory.make_Node(status=NODE_STATUS.READY, with_boot_disk=True) mock_get_curtin_config = self.patch(node_action_module, 'get_curtin_config') mock_node_start = self.patch(node, 'start') action = Deploy(node, user) action.execute() self.expectThat(mock_get_curtin_config, MockCalledOnceWith(node)) self.expectThat(mock_node_start, MockCalledOnceWith(user)) self.expectThat(user, Equals(node.owner)) self.expectThat(NODE_STATUS.ALLOCATED, Equals(node.status))
def test_Deploy_is_actionable_if_user_doesnt_have_ssh_keys(self): owner = factory.make_User() node = factory.make_Node(interface=True, status=NODE_STATUS.ALLOCATED, power_type='manual', owner=owner) self.assertTrue(Deploy(node, owner).is_actionable())
def test_Deploy_returns_error_when_no_more_static_IPs(self): user = factory.make_User() network = IPNetwork("10.0.0.0/30") subnet = factory.make_Subnet(cidr=str(network.cidr)) rack_controller = factory.make_RackController() subnet.vlan.dhcp_on = True subnet.vlan.primary_rack = rack_controller subnet.vlan.save() node = factory.make_Node( status=NODE_STATUS.ALLOCATED, power_type='virsh', owner=user, power_state=POWER_STATE.OFF, bmc_connected_to=rack_controller) interface = factory.make_Interface( INTERFACE_TYPE.PHYSICAL, node=node, vlan=subnet.vlan) factory.make_StaticIPAddress( alloc_type=IPADDRESS_TYPE.AUTO, ip="", subnet=subnet, interface=interface) # Pre-claim the only addresses. with transaction.atomic(): StaticIPAddress.objects.allocate_new( subnet, requested_address="10.0.0.1") StaticIPAddress.objects.allocate_new( subnet, requested_address="10.0.0.2") StaticIPAddress.objects.allocate_new( subnet, requested_address="10.0.0.3") e = self.assertRaises(NodeActionError, Deploy(node, user).execute) self.expectThat( str(e), Equals( "%s: Failed to start, static IP addresses are exhausted." % node.hostname)) self.assertEqual(NODE_STATUS.ALLOCATED, node.status)
def test_Deploy_raises_NodeActionError_for_no_curtin_config(self): user = factory.make_User() node = factory.make_Node(interface=True, status=NODE_STATUS.ALLOCATED, power_type='manual', owner=user) mock_get_curtin_config = self.patch(node_action_module, 'get_curtin_config') mock_get_curtin_config.side_effect = NodeActionError('error') error = self.assertRaises(NodeActionError, Deploy(node, user).execute) self.assertEqual("Failed to retrieve curtin config: error", str(error))
def test_Deploy_starts_node(self): user = factory.make_User() node = factory.make_Node(interface=True, status=NODE_STATUS.ALLOCATED, power_type='manual', owner=user) mock_get_curtin_config = self.patch(node_action_module, 'get_curtin_config') mock_node_start = self.patch(node, 'start') Deploy(node, user).execute() self.expectThat(mock_get_curtin_config, MockCalledOnceWith(node)) self.expectThat(mock_node_start, MockCalledOnceWith(user))
def test_Deploy_raises_NodeActionError_for_invalid_os(self): user = factory.make_User() node = factory.make_Node(interface=True, status=NODE_STATUS.ALLOCATED, power_type='manual', owner=user) self.patch(node, 'start') os_name = factory.make_name("os") release_name = factory.make_name("release") extra = { "osystem": os_name, "distro_series": release_name, } error = self.assertRaises(NodeActionError, Deploy(node, user).execute, **extra) self.assertEqual("['%s is not a support operating system.']" % os_name, str(error))
def test_Deploy_doesnt_set_osystem_and_series_if_series_missing(self): user = factory.make_User() node = factory.make_Node(interface=True, status=NODE_STATUS.ALLOCATED, power_type='manual', owner=user) mock_get_curtin_config = self.patch(node_action_module, 'get_curtin_config') mock_node_start = self.patch(node, 'start') osystem = make_osystem_with_releases(self) extra = { "osystem": osystem["name"], } Deploy(node, user).execute(**extra) self.expectThat(mock_get_curtin_config, MockCalledOnceWith(node)) self.expectThat(mock_node_start, MockCalledOnceWith(user)) self.expectThat(node.osystem, Equals("")) self.expectThat(node.distro_series, Equals(""))
def test_Deploy_sets_osystem_and_series_strips_license_key_token(self): user = factory.make_User() node = factory.make_Node(interface=True, status=NODE_STATUS.ALLOCATED, power_type='manual', owner=user) mock_get_curtin_config = self.patch(node_action_module, 'get_curtin_config') mock_node_start = self.patch(node, 'start') osystem = make_usable_osystem(self) os_name = osystem["name"] release_name = osystem["releases"][0]["name"] extra = {"osystem": os_name, "distro_series": release_name + '*'} Deploy(node, user).execute(**extra) self.expectThat(mock_get_curtin_config, MockCalledOnceWith(node)) self.expectThat(mock_node_start, MockCalledOnceWith(user)) self.expectThat(node.osystem, Equals(os_name)) self.expectThat(node.distro_series, Equals(release_name))
def test_Deploy_inhibit_allows_user_without_SSH_key(self): user_without_key = factory.make_User() action = Deploy(factory.make_Node(), user_without_key) inhibition = action.inhibit() self.assertIsNone(inhibition)
def test_Deploy_inhibit_allows_user_with_SSH_key(self): user_with_key = factory.make_User() factory.make_SSHKey(user_with_key) self.assertIsNone(Deploy(factory.make_Node(), user_with_key).inhibit())