Example #1
0
 def test_delete_non_default_node_group_reset_node_to_error(
         self, _, notify):
     node_group = self.env.create_node_group(api=False,
                                             cluster_id=self.cluster.id)
     self.env._create_network_group(cluster=self.cluster,
                                    group_id=node_group.id)
     node2 = self.env.create_node(group_id=node_group.id,
                                  roles=['compute'],
                                  status=consts.NODE_STATUSES.provisioned,
                                  cluster_id=self.cluster.id,
                                  ip='10.3.0.42')
     task = self.env.launch_deployment()
     NailgunReceiver.deploy_resp(
         task_uuid=task.uuid,
         status=consts.TASK_STATUSES.ready,
         progress=100,
         nodes=[{'uid': n.uid, 'status': consts.NODE_STATUSES.ready,
                 'progress': 100}
                for n in self.env.nodes],
     )
     reset_task = self.env.reset_environment()
     NailgunReceiver.reset_environment_resp(
         task_uuid=reset_task.uuid,
         status=consts.TASK_STATUSES.ready,
         progress=100,
         nodes=[{'uid': n.uid}
                for n in self.env.nodes],
     )
     self.env.delete_node_group(node_group.id)
     self.assertEqual(node2.status, consts.NODE_STATUSES.error)
     self.assertEqual(node2.error_type, consts.NODE_ERRORS.discover)
     self.assertIsNone(node2.cluster)
     notify.assert_called()
    def test_stop_provisioning(self, _):
        provision_task = self.env.launch_provisioning_selected(
            self.node_uids
        )
        provision_task_uuid = provision_task.uuid
        NailgunReceiver.provision_resp(
            task_uuid=provision_task.uuid,
            status=consts.TASK_STATUSES.running,
            progress=50,
        )

        stop_task = self.env.stop_deployment()
        NailgunReceiver.stop_deployment_resp(
            task_uuid=stop_task.uuid,
            status=consts.TASK_STATUSES.ready,
            progress=100,
            nodes=[{'uid': n.uid} for n in self.env.nodes],
        )
        self.assertEqual(stop_task.status, consts.TASK_STATUSES.ready)
        self.assertTrue(self.db().query(Task).filter_by(
            uuid=provision_task_uuid
        ).first())
        self.assertIsNone(objects.Task.get_by_uuid(provision_task_uuid))

        self.assertEqual(self.cluster.status, consts.CLUSTER_STATUSES.stopped)
        self.assertEqual(stop_task.progress, 100)
        self.assertFalse(self.cluster.is_locked)
Example #3
0
    def test_deletion_during_deployment(self):
        cluster = self.env.create(cluster_kwargs={"name": u"Вася"},
                                  nodes_kwargs=[
                                      {
                                          "status": "ready",
                                          "pending_addition": True
                                      },
                                  ])
        resp = self.app.put(reverse('ClusterChangesHandler',
                                    kwargs={'cluster_id': cluster.id}),
                            headers=self.default_headers)
        deploy_uuid = resp.json_body['uuid']
        NailgunReceiver.provision_resp(
            task_uuid=deploy_uuid,
            status=consts.TASK_STATUSES.running,
            progress=50,
        )

        resp = self.app.delete(reverse('ClusterHandler',
                                       kwargs={'obj_id': cluster.id}),
                               headers=self.default_headers)
        task_delete = self.db.query(
            models.Task).filter_by(uuid=resp.json['uuid']).first()
        NailgunReceiver.remove_cluster_resp(
            task_uuid=task_delete.uuid,
            status=consts.TASK_STATUSES.ready,
            progress=100,
        )

        cluster = self.db.query(
            models.Cluster).filter_by(id=cluster.id).first()
        self.assertIsNone(cluster)
    def test_stop_provisioning(self):
        provision_task = self.env.launch_provisioning_selected(self.node_uids)
        provision_task_uuid = provision_task.uuid
        NailgunReceiver.provision_resp(
            task_uuid=provision_task.uuid,
            status=consts.TASK_STATUSES.running,
            progress=50,
        )

        stop_task = self.env.stop_deployment()
        NailgunReceiver.stop_deployment_resp(
            task_uuid=stop_task.uuid,
            status=consts.TASK_STATUSES.ready,
            progress=100,
            nodes=[{
                'uid': n.uid
            } for n in self.env.nodes],
        )
        self.assertEqual(stop_task.status, consts.TASK_STATUSES.ready)
        self.assertTrue(
            self.db().query(Task).filter_by(uuid=provision_task_uuid).first())
        self.assertIsNone(objects.Task.get_by_uuid(provision_task_uuid))

        self.assertEqual(self.cluster.status, consts.CLUSTER_STATUSES.stopped)
        self.assertEqual(stop_task.progress, 100)
        self.assertFalse(self.cluster.is_locked)
Example #5
0
    def test_check_repositories_resp_error(self, update_verify_networks):
        urls = ['url2', 'url1', 'url3', 'url1']
        repo_check_message = {
            "status":
            "ready",
            "progress":
            100,
            "task_uuid":
            self.task.uuid,
            "nodes": [{
                "status": 1,
                "out": {
                    "failed_urls": urls
                },
                "err": "",
                "uid": "1"
            }]
        }
        NailgunReceiver.check_repositories_resp(**repo_check_message)

        update_verify_networks.assert_called_with(self.task, 'error', 100, ANY,
                                                  [])
        actual_msg = update_verify_networks.call_args[0][3]
        expected_urls_set = set(urls)
        actual_urls = actual_msg.replace('"', '').replace(',', '').\
            split()[-len(expected_urls_set):]
        self.assertItemsEqual(expected_urls_set, actual_urls)
        self.assertRegexpMatches(
            actual_msg, r'These nodes: "1" failed to '
            'connect to some of these repositories: .*')
Example #6
0
 def test_success_action_with_plugins(self):
     NailgunReceiver._success_action(self.task, 'ready', 100)
     self.assertRegexpMatches(
         self.task.message, "Deployment of environment '[^\s]+' is done. "
         "\n\n"
         "Plugin name\d is deployed. description\d\n"
         "Plugin name\d is deployed. description\d")
Example #7
0
 def test_success_action_with_plugins(self):
     NailgunReceiver._success_action(self.task, 'ready', 100)
     self.assertRegexpMatches(
         self.task.message,
         "Deployment of environment '[^\s]+' is done. "
         "\n\n"
         "Plugin name\d is deployed. description\d\n"
         "Plugin name\d is deployed. description\d")
Example #8
0
 def test_transaction_resp_update_transaction_status(self, _):
     task = self.env.create_task(name=consts.TASK_NAMES.deployment,
                                 status=consts.TASK_STATUSES.running,
                                 cluster_id=self.cluster.id)
     NailgunReceiver.transaction_resp(task_uuid=task.uuid,
                                      status=consts.TASK_STATUSES.ready)
     self.db.refresh(task)
     self.assertEqual(consts.TASK_STATUSES.ready, task.status)
Example #9
0
 def test_notify_provision_sub_task(self, notify_checker):
     sub_task = self.env.create_task(name=consts.TASK_NAMES.provision,
                                     status=consts.TASK_STATUSES.ready,
                                     cluster_id=self.cluster.id,
                                     parent_id=self.task.id)
     NailgunReceiver._notify(sub_task, "done", "Test error.", "123",
                             sub_task.uuid)
     self.assertEqual(0, notify_checker.call_count)
Example #10
0
 def test_notify_deployment(self, notify_checker):
     NailgunReceiver._notify(self.task, "done", "Test error.", "123",
                             self.task.uuid)
     notify_checker.assert_called_with("done",
                                       u'Test error.',
                                       self.task.cluster_id,
                                       node_id="123",
                                       task_uuid=self.task.uuid)
Example #11
0
 def test_success_action_with_plugins(self):
     NailgunReceiver._success_action(self.task, 'ready', 100)
     self.assertRegexpMatches(
         self.task.message,
         "Deployment of environment '[^\s]+' is done. Access the OpenStack "
         "dashboard \(Horizon\) at [^\s]+\n"
         "\n"
         "Plugin name\d is deployed. description\d\n"
         "Plugin name\d is deployed. description\d")
Example #12
0
 def test_task_in_orchestrator_status_not_changed(self):
     resp = {'task_uuid': self.task.uuid}
     for status in (consts.TASK_STATUSES.error,
                    consts.TASK_STATUSES.running,
                    consts.TASK_STATUSES.ready):
         self.task.status = status
         self.db.flush()
         NailgunReceiver.task_in_orchestrator(**resp)
         self.assertEqual(status, self.task.status)
Example #13
0
 def test_task_in_orchestrator_status_not_changed(self):
     resp = {'task_uuid': self.task.uuid}
     for status in (consts.TASK_STATUSES.error,
                    consts.TASK_STATUSES.running,
                    consts.TASK_STATUSES.ready):
         self.task.status = status
         self.db.flush()
         NailgunReceiver.task_in_orchestrator(**resp)
         self.assertEqual(status, self.task.status)
Example #14
0
 def test_success_action_with_plugins(self):
     NailgunReceiver._success_action(self.task, 'ready', 100)
     self.assertRegexpMatches(
         self.task.message,
         "Deployment of environment '[^\s]+' is done. Access the OpenStack "
         "dashboard \(Horizon\) at [^\s]+\n"
         "\n"
         "Plugin name\d is deployed. description\d\n"
         "Plugin name\d is deployed. description\d")
Example #15
0
 def test_multiline_error_message(self, mnotify):
     task_resp = {
         "status": "error",
         "task_uuid": self.task.uuid,
         "error": "Method granular_deploy.\n\n Something Something"
     }
     NailgunReceiver.deploy_resp(**task_resp)
     mnotify.assert_called_with(
         task_resp['status'],
         u'Deployment has failed. Method granular_deploy.', self.cluster.id)
Example #16
0
 def test_multiline_error_message(self, mnotify):
     task_resp = {
         "status": "error",
         "task_uuid": self.task.uuid,
         "error": "Method granular_deploy.\n\n Something Something"}
     NailgunReceiver.deploy_resp(**task_resp)
     mnotify.assert_called_with(
         task_resp['status'],
         u'Deployment has failed. Method granular_deploy.',
         self.cluster.id)
Example #17
0
 def test_transaction_resp_update_transaction_status(self, _):
     task = self.env.create_task(
         name=consts.TASK_NAMES.deployment,
         status=consts.TASK_STATUSES.running,
         cluster_id=self.cluster.id
     )
     NailgunReceiver.transaction_resp(
         task_uuid=task.uuid,
         status=consts.TASK_STATUSES.ready
     )
     self.db.refresh(task)
     self.assertEqual(consts.TASK_STATUSES.ready, task.status)
Example #18
0
 def test_notify_deployment_sub_task(self, notify_checker):
     sub_task = self.env.create_task(name=consts.TASK_NAMES.deployment,
                                     status=consts.TASK_STATUSES.ready,
                                     cluster_id=self.cluster.id,
                                     parent_id=self.task.id)
     NailgunReceiver._notify(sub_task, "done", "Test error.", "123",
                             sub_task.uuid)
     notify_checker.assert_called_with("done",
                                       u'Test error.',
                                       sub_task.cluster_id,
                                       node_id="123",
                                       task_uuid=sub_task.uuid)
Example #19
0
    def test_check_repositories_resp_success(self, update_verify_networks):
        repo_check_message = {
            "status": "ready",
            "progress": 100,
            "task_uuid": self.task.uuid,
            "nodes": [{
                "status": 0,
                "err": "",
                "out": "",
                "uid": "1"}]}
        NailgunReceiver.check_repositories_resp(**repo_check_message)

        update_verify_networks.assert_called_with(
            self.task, 'ready', 100, '', [])
Example #20
0
    def test_check_repositories_resp_success(self, update_verify_networks):
        repo_check_message = {
            "status": "ready",
            "progress": 100,
            "task_uuid": self.task.uuid,
            "nodes": [{
                "status": 0,
                "err": "",
                "out": "",
                "uid": "1"}]}
        NailgunReceiver.check_repositories_resp(**repo_check_message)

        update_verify_networks.assert_called_with(
            self.task, 'ready', 100, '', [])
Example #21
0
 def test_notify_provision_sub_task(self, notify_checker):
     sub_task = self.env.create_task(
         name=consts.TASK_NAMES.provision,
         status=consts.TASK_STATUSES.ready,
         cluster_id=self.cluster.id,
         parent_id=self.task.id
     )
     NailgunReceiver._notify(
         sub_task,
         "done",
         "Test error.",
         "123",
         sub_task.uuid
     )
     self.assertEqual(0, notify_checker.call_count)
Example #22
0
 def test_notify_deployment(self, notify_checker):
     NailgunReceiver._notify(
         self.task,
         "done",
         "Test error.",
         "123",
         self.task.uuid
     )
     notify_checker.assert_called_with(
         "done",
         u'Test error.',
         self.task.cluster_id,
         node_id="123",
         task_uuid=self.task.uuid
     )
Example #23
0
    def test_master_uid_in_deploy_resp(self):
        node_resp = {
            "task_uuid": self.task.uuid,
            "nodes": [
                {"status": "error", "hook": None, "error_type": "deploy",
                 "role": "hook", "uid": "master"}]}
        NailgunReceiver.deploy_resp(**node_resp)
        self.assertEqual(self.task.status, 'error')

        task_resp = {
            "status": "error",
            "task_uuid": self.task.uuid,
            "error": "Method granular_deploy."}
        NailgunReceiver.deploy_resp(**task_resp)
        self.assertEqual(self.task.status, 'error')
        self.assertIn(task_resp['error'], self.task.message)
Example #24
0
    def test_master_uid_in_deploy_resp(self):
        node_resp = {
            "task_uuid": self.task.uuid,
            "nodes": [
                {"status": "error", "hook": None, "error_type": "deploy",
                 "role": "hook", "uid": "master"}]}
        NailgunReceiver.deploy_resp(**node_resp)
        self.assertEqual(self.task.status, 'error')

        task_resp = {
            "status": "error",
            "task_uuid": self.task.uuid,
            "error": "Method granular_deploy."}
        NailgunReceiver.deploy_resp(**task_resp)
        self.assertEqual(self.task.status, 'error')
        self.assertIn(task_resp['error'], self.task.message)
Example #25
0
 def test_transaction_resp_update_node_attributes(self):
     task = self.env.create_task(name=consts.TASK_NAMES.deployment,
                                 status=consts.TASK_STATUSES.running,
                                 cluster_id=self.cluster.id)
     node = self.cluster.nodes[0]
     node.status = consts.NODE_STATUSES.provisioned
     node.progress = 1
     node.pending_addition = True
     NailgunReceiver.transaction_resp(task_uuid=task.uuid,
                                      nodes=[{
                                          'uid': node.uid,
                                          'progress': 50,
                                          'pending_addition': False
                                      }])
     self.db.refresh(node)
     self.assertEqual(50, node.progress)
     self.assertFalse(node.pending_addition)
Example #26
0
    def test_check_repositories_resp_error(self, update_verify_networks):
        urls = ['url1', 'url2']
        repo_check_message = {
            "status": "ready",
            "progress": 100,
            "task_uuid": self.task.uuid,
            "nodes": [{
                "status": 1,
                "out": {"failed_urls": urls},
                "err": "",
                "uid": "1"}]}
        NailgunReceiver.check_repositories_resp(**repo_check_message)

        update_verify_networks.assert_called_with(
            self.task, 'error', 100,
            ('These nodes: "1" failed to '
             'connect to some of these repositories: "url1", "url2"'), [])
    def test_config_execute_fails_if_deployment_running(self, mocked_rpc):
        task_manager = OpenstackConfigTaskManager(self.cluster.id)
        task = task_manager.execute({'cluster_id': self.cluster.id})

        self.assertEqual(task.status, consts.TASK_STATUSES.pending)

        NailgunReceiver.deploy_resp(
            task_uuid=task.uuid,
            status=consts.TASK_STATUSES.running,
            progress=50,
            nodes=[{'uid': n.uid, 'status': consts.NODE_STATUSES.ready}
                   for n in self.env.nodes],
        )

        self.assertEqual(task.status, consts.TASK_STATUSES.running)
        task2 = OpenstackConfigTaskManager(self.cluster.id)
        self.assertRaises(errors.TaskAlreadyRunning,
                          task2.execute, {'cluster_id': self.cluster.id})
Example #28
0
    def test_stop_deployment(self):
        supertask = self.env.launch_deployment()
        self.assertEqual(supertask.status, consts.TASK_STATUSES.pending)

        deploy_task = [t for t in supertask.subtasks
                       if t.name in (consts.TASK_NAMES.deployment)][0]

        NailgunReceiver.deploy_resp(
            task_uuid=deploy_task.uuid,
            status=consts.TASK_STATUSES.running,
            progress=50,
        )

        stop_task = self.env.stop_deployment()
        NailgunReceiver.stop_deployment_resp(
            task_uuid=stop_task.uuid,
            status=consts.TASK_STATUSES.ready,
            progress=100,
            nodes=[{'uid': n.uid} for n in self.env.nodes],
        )
        self.assertEqual(stop_task.status, consts.TASK_STATUSES.ready)

        self.assertTrue(self.db().query(Task).filter_by(
            uuid=deploy_task.uuid
        ).first())
        self.assertIsNone(objects.Task.get_by_uuid(deploy_task.uuid))

        self.assertEqual(self.cluster.status,
                         consts.CLUSTER_STATUSES.stopped)
        self.assertEqual(stop_task.progress, 100)
        self.assertFalse(self.cluster.is_locked)

        for n in self.cluster.nodes:
            self.assertEqual(n.roles, [])
            self.assertNotEqual(n.pending_roles, [])

        notification = self.db.query(Notification).filter_by(
            cluster_id=stop_task.cluster_id
        ).order_by(
            Notification.datetime.desc()
        ).first()
        self.assertRegexpMatches(
            notification.message,
            'was successfully stopped')
Example #29
0
    def test_stop_deployment(self):
        supertask = self.env.launch_deployment()
        self.assertEqual(supertask.status, consts.TASK_STATUSES.pending)

        deploy_task = [
            t for t in supertask.subtasks
            if t.name == consts.TASK_NAMES.deployment
        ][0]

        NailgunReceiver.deploy_resp(
            task_uuid=deploy_task.uuid,
            status=consts.TASK_STATUSES.running,
            progress=50,
        )

        stop_task = self.env.stop_deployment()
        NailgunReceiver.stop_deployment_resp(
            task_uuid=stop_task.uuid,
            status=consts.TASK_STATUSES.ready,
            progress=100,
            nodes=[{
                'uid': n.uid
            } for n in self.env.nodes],
        )
        self.assertEqual(stop_task.status, consts.TASK_STATUSES.ready)

        self.assertTrue(
            self.db().query(Task).filter_by(uuid=deploy_task.uuid).first())
        self.assertIsNone(objects.Task.get_by_uuid(deploy_task.uuid))

        self.assertEqual(self.cluster.status, consts.CLUSTER_STATUSES.stopped)
        self.assertEqual(stop_task.progress, 100)
        self.assertFalse(self.cluster.is_locked)

        for n in self.cluster.nodes:
            self.assertEqual(n.roles, [])
            self.assertNotEqual(n.pending_roles, [])

        notification = self.db.query(Notification).filter_by(
            cluster_id=stop_task.cluster_id).order_by(
                Notification.datetime.desc()).first()
        self.assertRegexpMatches(notification.message,
                                 'was successfully stopped')
Example #30
0
 def test_transaction_resp_update_node_attributes(self):
     task = self.env.create_task(
         name=consts.TASK_NAMES.deployment,
         status=consts.TASK_STATUSES.running,
         cluster_id=self.cluster.id
     )
     node = self.cluster.nodes[0]
     node.status = consts.NODE_STATUSES.provisioned
     node.progress = 1
     node.pending_addition = True
     NailgunReceiver.transaction_resp(
         task_uuid=task.uuid,
         nodes=[{
             'uid': node.uid, 'progress': 50, 'pending_addition': False
         }]
     )
     self.db.refresh(node)
     self.assertEqual(50, node.progress)
     self.assertFalse(node.pending_addition)
Example #31
0
    def test_transaction_resp_does_not_fail_on_virtual_nodes(self):
        task = self.env.create_task(name=consts.TASK_NAMES.deployment,
                                    status=consts.TASK_STATUSES.running,
                                    cluster_id=self.cluster.id,
                                    dry_run=True)

        NailgunReceiver.transaction_resp(
            task_uuid=task.uuid,
            status=consts.TASK_STATUSES.running,
            nodes=[
                {
                    'uid': consts.MASTER_NODE_UID,
                    'status': consts.NODE_STATUSES.provisioned,
                },
                {
                    # cluster node uid is null
                    'uid': None,
                    'status': consts.NODE_STATUSES.provisioned,
                },
            ])
Example #32
0
    def test_deletion_during_deployment(self, mock_rpc):
        self.env.create(
            cluster_kwargs={
                "name": u"Вася"
            },
            nodes_kwargs=[
                {"status": "ready", "pending_addition": True},
            ]
        )
        cluster_id = self.env.clusters[0].id
        resp = self.app.put(
            reverse(
                'ClusterChangesHandler',
                kwargs={'cluster_id': cluster_id}),
            headers=self.default_headers
        )
        deploy_uuid = resp.json_body['uuid']
        NailgunReceiver.provision_resp(
            task_uuid=deploy_uuid,
            status=consts.TASK_STATUSES.running,
            progress=50,
        )

        resp = self.app.delete(
            reverse(
                'ClusterHandler',
                kwargs={'obj_id': cluster_id}),
            headers=self.default_headers
        )
        task_delete = self.db.query(models.Task).filter_by(
            uuid=resp.json['uuid']
        ).first()
        NailgunReceiver.remove_cluster_resp(
            task_uuid=task_delete.uuid,
            status=consts.TASK_STATUSES.ready,
            progress=100,
        )

        cluster = self.db.query(models.Cluster).filter_by(
            id=cluster_id).first()
        self.assertIsNone(cluster)
Example #33
0
 def test_notify_deployment_sub_task(self, notify_checker):
     sub_task = self.env.create_task(
         name=consts.TASK_NAMES.deployment,
         status=consts.TASK_STATUSES.ready,
         cluster_id=self.cluster.id,
         parent_id=self.task.id
     )
     NailgunReceiver._notify(
         sub_task,
         "done",
         "Test error.",
         "123",
         sub_task.uuid
     )
     notify_checker.assert_called_with(
         "done",
         u'Test error.',
         sub_task.cluster_id,
         node_id="123",
         task_uuid=sub_task.uuid
     )
    def test_stop_deployment_fail_if_deployed_before(self):
        task = self.env.launch_deployment()

        deploy_task = [
            t for t in task.subtasks if t.name == consts.TASK_NAMES.deployment
        ][0]

        # In objects/task.py cluster status is set to operational. Cluster
        # function __update_cluster_status checks if nodes are in
        # expected_node_status, and if they are - then
        # set_deployed_before_flag is set. This flag is used to determine if
        # cluster was ever deployed before.
        NailgunReceiver.deploy_resp(
            task_uuid=deploy_task.uuid,
            status=consts.TASK_STATUSES.ready,
            progress=100,
            nodes=[{
                'uid': n.uid,
                'status': consts.NODE_STATUSES.ready
            } for n in self.env.nodes],
        )
        # If we don't send 'ready' for main task, then redeploy can't be
        # started - as we still have deployment running
        # TODO(mihgen): investigate why DeploymentAlreadyStarted is unhandled
        for sub_task in task.subtasks:
            NailgunReceiver.deploy_resp(
                task_uuid=sub_task.uuid,
                status=consts.TASK_STATUSES.ready,
            )

        # changes to deploy
        self.env.create_node(cluster_id=self.cluster.id,
                             roles=["controller"],
                             pending_addition=True)

        supertask = self.env.launch_deployment()
        redeploy_task = [
            t for t in supertask.subtasks
            if t.name == consts.TASK_NAMES.deployment
        ][0]
        NailgunReceiver.deploy_resp(
            task_uuid=redeploy_task.uuid,
            status=consts.TASK_STATUSES.running,
            progress=50,
        )

        # stop task will not be created as in this situation
        # the error will be raised by validator thus we cannot use
        # self.env.stop_deployment to check the result
        resp = self.app.put(reverse('ClusterStopDeploymentHandler',
                                    kwargs={'cluster_id': self.cluster.id}),
                            expect_errors=True,
                            headers=self.default_headers)

        self.assertEqual(resp.status_code, 400)
        self.assertEqual(
            resp.json_body['message'],
            'Stop action is forbidden for the cluster. Current '
            'deployment process is running on a pre-deployed '
            'cluster that does not support LCM.')
Example #35
0
    def test_transaction_resp_does_not_fail_on_virtual_nodes(self):
        task = self.env.create_task(
            name=consts.TASK_NAMES.deployment,
            status=consts.TASK_STATUSES.running,
            cluster_id=self.cluster.id,
            dry_run=True
        )

        NailgunReceiver.transaction_resp(
            task_uuid=task.uuid,
            status=consts.TASK_STATUSES.running,
            nodes=[
                {
                    'uid': consts.MASTER_NODE_UID,
                    'status': consts.NODE_STATUSES.provisioned,
                },
                {
                    # cluster node uid is null
                    'uid': None,
                    'status': consts.NODE_STATUSES.provisioned,
                },
            ])
Example #36
0
    def test_stop_deployment_fail_if_deployed_before(self):
        task = self.env.launch_deployment()

        deploy_task = [t for t in task.subtasks
                       if t.name == consts.TASK_NAMES.deployment][0]

        # In objects/task.py cluster status is set to operational. Cluster
        # function __update_cluster_status checks if nodes are in
        # expected_node_status, and if they are - then
        # set_deployed_before_flag is set. This flag is used to determine if
        # cluster was ever deployed before.
        NailgunReceiver.deploy_resp(
            task_uuid=deploy_task.uuid,
            status=consts.TASK_STATUSES.ready,
            progress=100,
            nodes=[{'uid': n.uid, 'status': consts.NODE_STATUSES.ready}
                   for n in self.env.nodes],
        )
        # If we don't send 'ready' for main task, then redeploy can't be
        # started - as we still have deployment running
        # TODO(mihgen): investigate why DeploymentAlreadyStarted is unhandled
        NailgunReceiver.deploy_resp(
            task_uuid=task.uuid,
            status=consts.TASK_STATUSES.ready,
        )

        # changes to deploy
        self.env.create_node(
            cluster_id=self.cluster.id,
            roles=["controller"],
            pending_addition=True
        )

        supertask = self.env.launch_deployment()
        redeploy_task = [t for t in supertask.subtasks
                         if t.name == consts.TASK_NAMES.deployment][0]
        NailgunReceiver.deploy_resp(
            task_uuid=redeploy_task.uuid,
            status=consts.TASK_STATUSES.running,
            progress=50,
        )

        # stop task will not be created as in this situation
        # the error will be raised by validator thus we cannot use
        # self.env.stop_deployment to check the result
        resp = self.app.put(
            reverse(
                'ClusterStopDeploymentHandler',
                kwargs={'cluster_id': self.cluster.id}),
            expect_errors=True,
            headers=self.default_headers
        )

        self.assertEqual(resp.status_code, 400)
        self.assertEqual(resp.json_body['message'],
                         'Stop action is forbidden for the cluster. Current '
                         'deployment process is running on a pre-deployed '
                         'cluster that does not support LCM.')
Example #37
0
 def test_transaction_resp_does_not_update_nodes_if_dry_run(self, _):
     task = self.env.create_task(name=consts.TASK_NAMES.deployment,
                                 status=consts.TASK_STATUSES.running,
                                 cluster_id=self.cluster.id,
                                 dry_run=True)
     self.cluster.status = consts.CLUSTER_STATUSES.operational
     node = self.cluster.nodes[0]
     node.status = consts.NODE_STATUSES.provisioned
     NailgunReceiver.transaction_resp(task_uuid=task.uuid,
                                      status=consts.TASK_STATUSES.ready,
                                      nodes=[{
                                          'uid':
                                          node.uid,
                                          'status':
                                          consts.NODE_STATUSES.ready
                                      }])
     self.db.refresh(task)
     self.db.refresh(node)
     self.db.refresh(self.cluster)
     self.assertEqual(consts.TASK_STATUSES.ready, task.status)
     self.assertEqual(consts.NODE_STATUSES.provisioned, node.status)
     self.assertEqual(consts.CLUSTER_STATUSES.operational,
                      self.cluster.status)
Example #38
0
    def test_deletion_during_deployment(self):
        cluster = self.env.create(cluster_kwargs={"name": u"Вася"},
                                  nodes_kwargs=[
                                      {
                                          "status": "ready",
                                          "pending_addition": True
                                      },
                                  ])
        resp = self.app.put(reverse('ClusterChangesHandler',
                                    kwargs={'cluster_id': cluster.id}),
                            headers=self.default_headers)
        deploy_uuid = resp.json_body['uuid']
        NailgunReceiver.provision_resp(
            task_uuid=deploy_uuid,
            status=consts.TASK_STATUSES.running,
            progress=50,
        )

        resp = self.app.delete(reverse('ClusterHandler',
                                       kwargs={'obj_id': cluster.id}),
                               headers=self.default_headers,
                               expect_errors=True)
        self.assertEqual(400, resp.status_code)
Example #39
0
 def test_transaction_resp_does_not_update_nodes_if_dry_run(self, _):
     task = self.env.create_task(
         name=consts.TASK_NAMES.deployment,
         status=consts.TASK_STATUSES.running,
         cluster_id=self.cluster.id,
         dry_run=True
     )
     self.cluster.status = consts.CLUSTER_STATUSES.operational
     node = self.cluster.nodes[0]
     node.status = consts.NODE_STATUSES.provisioned
     NailgunReceiver.transaction_resp(
         task_uuid=task.uuid,
         status=consts.TASK_STATUSES.ready,
         nodes=[{'uid': node.uid, 'status': consts.NODE_STATUSES.ready}]
     )
     self.db.refresh(task)
     self.db.refresh(node)
     self.db.refresh(self.cluster)
     self.assertEqual(consts.TASK_STATUSES.ready, task.status)
     self.assertEqual(consts.NODE_STATUSES.provisioned, node.status)
     self.assertEqual(
         consts.CLUSTER_STATUSES.operational, self.cluster.status
     )
Example #40
0
    def test_check_repositories_resp_error(self, update_verify_networks):
        urls = ['url2', 'url1', 'url3', 'url1']
        repo_check_message = {
            "status": "ready",
            "progress": 100,
            "task_uuid": self.task.uuid,
            "nodes": [{
                "status": 1,
                "out": {"failed_urls": urls},
                "err": "",
                "uid": "1"}]}
        NailgunReceiver.check_repositories_resp(**repo_check_message)

        update_verify_networks.assert_called_with(
            self.task, 'error', 100, ANY, [])
        actual_msg = update_verify_networks.call_args[0][3]
        expected_urls_set = set(urls)
        actual_urls = actual_msg.replace('"', '').replace(',', '').\
            split()[-len(expected_urls_set):]
        self.assertItemsEqual(expected_urls_set, actual_urls)
        self.assertRegexpMatches(
            actual_msg,
            r'These nodes: "1" failed to '
            'connect to some of these repositories: .*')
Example #41
0
 def test_delete_non_default_node_group_reset_node_to_error(
         self, _, notify):
     node_group = self.env.create_node_group(api=False,
                                             cluster_id=self.cluster.id)
     self.env._create_network_group(cluster=self.cluster,
                                    group_id=node_group.id)
     node2 = self.env.create_node(group_id=node_group.id,
                                  roles=['compute'],
                                  status=consts.NODE_STATUSES.provisioned,
                                  cluster_id=self.cluster.id,
                                  ip='10.3.0.42')
     task = self.env.launch_deployment()
     NailgunReceiver.deploy_resp(
         task_uuid=task.uuid,
         status=consts.TASK_STATUSES.ready,
         progress=100,
         nodes=[{
             'uid': n.uid,
             'status': consts.NODE_STATUSES.ready,
             'progress': 100
         } for n in self.env.nodes],
     )
     reset_task = self.env.reset_environment()
     NailgunReceiver.reset_environment_resp(
         task_uuid=reset_task.uuid,
         status=consts.TASK_STATUSES.ready,
         progress=100,
         nodes=[{
             'uid': n.uid
         } for n in self.env.nodes],
     )
     self.env.delete_node_group(node_group.id)
     self.assertEqual(node2.status, consts.NODE_STATUSES.error)
     self.assertEqual(node2.error_type, consts.NODE_ERRORS.discover)
     self.assertIsNone(node2.cluster)
     notify.assert_called()
Example #42
0
    def test_check_repositories_resp_error(self, update_verify_networks):
        urls = ['url1', 'url2']
        repo_check_message = {
            "status":
            "ready",
            "progress":
            100,
            "task_uuid":
            self.task.uuid,
            "nodes": [{
                "status": 1,
                "out": {
                    "failed_urls": urls
                },
                "err": "",
                "uid": "1"
            }]
        }
        NailgunReceiver.check_repositories_resp(**repo_check_message)

        update_verify_networks.assert_called_with(
            self.task, 'error', 100,
            ('These nodes: "1" failed to '
             'connect to some of these repositories: "url1", "url2"'), [])
Example #43
0
    def process(self, transaction, report):
        """Process feedback from executor (Astute).

        :param transaction: a transaction to handle (sibling, not top level)
        :param report: a report to process
        """
        nodes = report.get('nodes', [])
        error = report.get('error')
        status = report.get('status')
        progress = report.get('progress')

        # Report may contain two virtual nodes: master and cluster ('None').
        # Since we don't have them in database we should ensure we ain't
        # going to update them.
        nodes_params = {
            str(node['uid']): node for node in nodes
            if node['uid'] not in (consts.MASTER_NODE_UID, None)
        }
        nodes_instances = objects.NodeCollection.lock_for_update(
            objects.NodeCollection.filter_by_list(
                None, 'id', nodes_params.keys(), order_by=('id', )
            )
        ).all()

        _update_nodes(transaction, nodes_instances, nodes_params)
        _update_history(transaction, nodes)

        if status:
            # FIXME: resolve circular dependencies by moving assemble task
            # updates from receiver to objects layer.
            from nailgun.rpc.receiver import NailgunReceiver
            objects.Task.update_recursively(
                transaction,
                NailgunReceiver._assemble_task_update(
                    transaction, status, progress, error, nodes_instances
                )
            )

        # if transaction is completed successfully, we've got to initiate
        # the next one in the chain
        if transaction.parent and status == consts.TASK_STATUSES.ready:
            self.continue_(transaction.parent)
Example #44
0
 def test_task_in_orchestrator(self):
     resp = {'task_uuid': self.task.uuid}
     self.task.status = consts.TASK_STATUSES.pending
     self.db.flush()
     NailgunReceiver.task_in_orchestrator(**resp)
     self.assertEqual(consts.TASK_STATUSES.running, self.task.status)
Example #45
0
 def test_task_in_orchestrator(self):
     resp = {'task_uuid': self.task.uuid}
     self.task.status = consts.TASK_STATUSES.pending
     self.db.flush()
     NailgunReceiver.task_in_orchestrator(**resp)
     self.assertEqual(consts.TASK_STATUSES.running, self.task.status)