def test_NODE_TRANSITIONS_destination_state(self): all_destination_states = [] for destination_states in NODE_TRANSITIONS.values(): all_destination_states.extend(destination_states) allowed_states = set(NODE_STATUS_CHOICES_DICT.keys()) self.assertTrue(set(all_destination_states) <= allowed_states)
def clean_status(self): """Check a node's status transition against the node-status FSM.""" old_status = get_db_state(self, 'status') if self.status == old_status: # No transition is always a safe transition. pass elif self.status in NODE_TRANSITIONS.get(old_status, ()): # Valid transition. pass else: # Transition not permitted. error_text = "Invalid transition: %s -> %s." % ( NODE_STATUS_CHOICES_DICT.get(old_status, "Unknown"), NODE_STATUS_CHOICES_DICT.get(self.status, "Unknown"), ) raise NodeStateViolation(error_text)
def test_NODE_TRANSITIONS_initial_states(self): allowed_states = set(NODE_STATUS_CHOICES_DICT.keys() + [None]) self.assertTrue(set(NODE_TRANSITIONS.keys()) <= allowed_states)
) from maasserver.exceptions import Redirect from maasserver.node_action import ( AcceptAndCommission, compile_node_actions, Delete, NodeAction, RetryCommissioning, StartNode, ) from maasserver.testing.factory import factory from maasserver.testing.testcase import TestCase from provisioningserver.enum import POWER_TYPE ALL_STATUSES = NODE_STATUS_CHOICES_DICT.keys() class FakeNodeAction(NodeAction): display = "Action label" actionable_statuses = ALL_STATUSES permission = NODE_PERMISSION.VIEW # For testing: an inhibition for inhibit() to return. fake_inhibition = None def inhibit(self): return self.fake_inhibition def execute(self): pass
from maasserver.utils.orm import post_commit_do from maasserver.utils.osystems import ( validate_hwe_kernel, validate_osystem_and_distro_series, ) from metadataserver.enum import SCRIPT_STATUS from provisioningserver.events import EVENT_TYPES from provisioningserver.rpc.exceptions import ( NoConnectionsAvailable, PowerActionAlreadyInProgress, ) from provisioningserver.utils.enum import map_enum from provisioningserver.utils.shell import ExternalProcessError # All node statuses. ALL_STATUSES = set(NODE_STATUS_CHOICES_DICT.keys()) # A collection of errors that may be raised by RPC-based actions that # should be converted to NodeActionErrors. RPC_EXCEPTIONS = ( NoConnectionsAvailable, PowerActionAlreadyInProgress, TimeoutError, ) class NodeAction(metaclass=ABCMeta): """Base class for node actions.""" name = abstractproperty(""" Action name.
from django.core.urlresolvers import reverse from maasserver.enum import ( NODE_PERMISSION, NODE_STATUS, NODE_STATUS_CHOICES_DICT, ) from maasserver.exceptions import Redirect from maasserver.models import ( Node, SSHKey, ) from maasserver.utils import map_enum # All node statuses. ALL_STATUSES = set(NODE_STATUS_CHOICES_DICT.keys()) class NodeAction: """Base class for node actions.""" __metaclass__ = ABCMeta name = abstractproperty(""" Action name. Will be used as the name for the action in all the forms. """) display = abstractproperty(""" Action name.