Merge "New command "openstack overcloud node unprovision""
This commit is contained in:
commit
68b56c694b
10
releasenotes/notes/node-unprovision-dd400e58f2f479a2.yaml
Normal file
10
releasenotes/notes/node-unprovision-dd400e58f2f479a2.yaml
Normal file
@ -0,0 +1,10 @@
|
||||
features:
|
||||
- |
|
||||
New command "openstack overcloud node unprovision"
|
||||
|
||||
This is a companion command to "openstack overcloud node provision"
|
||||
which is required for scale-down and should be run after "openstack
|
||||
overcloud deploy".
|
||||
|
||||
It will undeploy any instance which has provisioned=False in the
|
||||
supplied roles yaml.
|
@ -76,6 +76,7 @@ openstack.tripleoclient.v1 =
|
||||
overcloud_node_bios_configure = tripleoclient.v1.overcloud_bios:ConfigureBIOS
|
||||
overcloud_node_bios_reset = tripleoclient.v1.overcloud_bios:ResetBIOS
|
||||
overcloud_node_provision = tripleoclient.v1.overcloud_node:ProvisionNode
|
||||
overcloud_node_unprovision = tripleoclient.v1.overcloud_node:UnprovisionNode
|
||||
overcloud_parameters_set = tripleoclient.v1.overcloud_parameters:SetParameters
|
||||
overcloud_plan_create = tripleoclient.v1.overcloud_plan:CreatePlan
|
||||
overcloud_plan_delete = tripleoclient.v1.overcloud_plan:DeletePlan
|
||||
|
@ -1099,3 +1099,41 @@ class TestProvisionNode(fakes.TestOvercloudNode):
|
||||
'ssh_keys': ['I am a key'],
|
||||
'ssh_user_name': 'heat-admin'}
|
||||
)
|
||||
|
||||
|
||||
class TestUnprovisionNode(fakes.TestOvercloudNode):
|
||||
|
||||
def setUp(self):
|
||||
super(TestUnprovisionNode, self).setUp()
|
||||
|
||||
self.workflow = self.app.client_manager.workflow_engine
|
||||
execution = mock.Mock()
|
||||
execution.id = "IDID"
|
||||
self.workflow.executions.create.return_value = execution
|
||||
client = self.app.client_manager.tripleoclient
|
||||
self.websocket = client.messaging_websocket()
|
||||
self.websocket.wait_for_messages.return_value = [{
|
||||
"status": "SUCCESS",
|
||||
"message": "Success",
|
||||
"environment": {"cat": "meow"},
|
||||
"execution": {"id": "IDID"}
|
||||
}]
|
||||
|
||||
self.cmd = overcloud_node.UnprovisionNode(self.app, None)
|
||||
|
||||
def test_ok(self):
|
||||
with tempfile.NamedTemporaryFile() as inp:
|
||||
inp.write(b'- name: Compute\n- name: Controller\n')
|
||||
inp.flush()
|
||||
argslist = [inp.name]
|
||||
verifylist = [('input', inp.name)]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd,
|
||||
argslist, verifylist)
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
self.workflow.executions.create.assert_called_once_with(
|
||||
'tripleo.baremetal_deploy.v1.undeploy_roles',
|
||||
workflow_input={'roles': [{'name': 'Compute'},
|
||||
{'name': 'Controller'}]}
|
||||
)
|
||||
|
@ -485,9 +485,9 @@ class DiscoverNode(command.Command):
|
||||
|
||||
|
||||
class ProvisionNode(command.Command):
|
||||
"""Provision a new node using Ironic."""
|
||||
"""Provision new nodes using Ironic."""
|
||||
|
||||
log = logging.getLogger(__name__ + ".DiscoverNode")
|
||||
log = logging.getLogger(__name__ + ".ProvisionNode")
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(ProvisionNode, self).get_parser(prog_name)
|
||||
@ -534,3 +534,31 @@ class ProvisionNode(command.Command):
|
||||
|
||||
print('Nodes deployed successfully, add %s to your deployment '
|
||||
'environment' % parsed_args.output)
|
||||
|
||||
|
||||
class UnprovisionNode(command.Command):
|
||||
"""Unprovisions nodes using Ironic."""
|
||||
|
||||
log = logging.getLogger(__name__ + ".UnprovisionNode")
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(UnprovisionNode, self).get_parser(prog_name)
|
||||
parser.add_argument('input',
|
||||
metavar='<baremetal_deployment.yaml>',
|
||||
help=_('Configuration file describing the '
|
||||
'baremetal deployment'))
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self.log.debug("take_action(%s)" % parsed_args)
|
||||
|
||||
with open(parsed_args.input, 'r') as fp:
|
||||
roles = yaml.safe_load(fp)
|
||||
|
||||
# TODO(sbaker) call ExpandRolesAction to get a list of
|
||||
# instances being unprovisioned to prompt for confirmation
|
||||
baremetal.undeploy_roles(
|
||||
self.app.client_manager,
|
||||
roles=roles)
|
||||
|
||||
print('Unprovision complete')
|
||||
|
@ -541,3 +541,30 @@ def deploy_roles(clients, **workflow_input):
|
||||
'Error deploying nodes: {}'.format(payload['message']))
|
||||
|
||||
return payload
|
||||
|
||||
|
||||
def undeploy_roles(clients, **workflow_input):
|
||||
"""Undeploy provided roles using Ironic.
|
||||
|
||||
Run the tripleo.baremetal_deploy.v1.undeploy_roles Mistral workflow.
|
||||
"""
|
||||
|
||||
workflow_client = clients.workflow_engine
|
||||
tripleoclients = clients.tripleoclient
|
||||
|
||||
with tripleoclients.messaging_websocket() as ws:
|
||||
execution = base.start_workflow(
|
||||
workflow_client,
|
||||
'tripleo.baremetal_deploy.v1.undeploy_roles',
|
||||
workflow_input=workflow_input
|
||||
)
|
||||
|
||||
for payload in base.wait_for_messages(workflow_client, ws, execution):
|
||||
if payload.get('message'):
|
||||
print(payload['message'])
|
||||
|
||||
if payload['status'] != 'SUCCESS':
|
||||
raise exceptions.NodeConfigurationError(
|
||||
'Error undeploying nodes: {}'.format(payload['message']))
|
||||
|
||||
return payload
|
||||
|
Loading…
Reference in New Issue
Block a user