Ejemplo n.º 1
0
 def test_33(self):
     with session_commit(sess_maker=self.sess_maker) as session:
         rq = "uuid=%s&mac=%s&os=installed" % (
             posts.M02["boot-info"]["uuid"], posts.M02["boot-info"]["mac"])
         i = crud.InjectLifecycle(session, request_raw_query=rq)
         i.refresh_lifecycle_ignition(True)
         j = crud.InjectLifecycle(session, request_raw_query=rq)
         j.refresh_lifecycle_ignition(True)
     f = crud.FetchLifecycle(sess_maker=self.sess_maker)
     self.assertTrue(
         f.get_ignition_uptodate_status(posts.M02["boot-info"]["mac"]))
Ejemplo n.º 2
0
    def test_36(self):
        with session_commit(sess_maker=self.sess_maker) as session:
            rq = "uuid=%s&mac=%s&os=installed" % (
                posts.M03["boot-info"]["uuid"], posts.M03["boot-info"]["mac"])
            i = crud.InjectLifecycle(session, request_raw_query=rq)
            i.apply_lifecycle_rolling(True)

        f = crud.FetchLifecycle(sess_maker=self.sess_maker)
        status = f.get_rolling_status(posts.M03["boot-info"]["mac"])
        self.assertTrue(status[0])
        self.assertEqual("kexec", status[1])

        with session_commit(sess_maker=self.sess_maker) as session:
            n = crud.InjectLifecycle(session, rq)
            n.apply_lifecycle_rolling(False)

        f = crud.FetchLifecycle(sess_maker=self.sess_maker)
        r = f.get_rolling_status(posts.M03["boot-info"]["mac"])
        self.assertFalse(r[0])
        self.assertEqual("kexec", r[1])

        with session_commit(sess_maker=self.sess_maker) as session:
            n = crud.InjectLifecycle(session, rq)
            n.apply_lifecycle_rolling(True, "reboot")

        f = crud.FetchLifecycle(sess_maker=self.sess_maker)
        r = f.get_rolling_status(posts.M03["boot-info"]["mac"])
        self.assertTrue(r[0])
        self.assertEqual("reboot", r[1])

        with session_commit(sess_maker=self.sess_maker) as session:
            n = crud.InjectLifecycle(session, rq)
            n.apply_lifecycle_rolling(True, "poweroff")

        f = crud.FetchLifecycle(sess_maker=self.sess_maker)
        r = f.get_rolling_status(posts.M03["boot-info"]["mac"])
        self.assertTrue(r[0])
        self.assertEqual("poweroff", r[1])

        with session_commit(sess_maker=self.sess_maker) as session:
            n = crud.InjectLifecycle(session, rq)
            with self.assertRaises(LookupError):
                n.apply_lifecycle_rolling(True, "notpossible")

        f = crud.FetchLifecycle(sess_maker=self.sess_maker)
        r = f.get_rolling_status(posts.M03["boot-info"]["mac"])
        self.assertTrue(r[0])
        self.assertEqual("poweroff", r[1])
Ejemplo n.º 3
0
    def lifecycle_rolling_delete(request_raw_query):
        """
        Lifecycle Rolling Update
        Disable the current policy for a given machine by UUID or MAC
        ---
        tags:
          - lifecycle
        parameters:
          - name: request_raw_query
            in: path
            description: Pass the mac as 'mac=<mac>'
            required: true
            type: string
        responses:
          200:
            description: Rolling Update is not enable
            schema:
                type: dict
        """
        app.logger.info("%s %s" % (request.method, request.url))

        with session_commit(sess_maker=sess_maker) as session:
            life = crud.InjectLifecycle(session, request_raw_query)
            life.apply_lifecycle_rolling(False, None)
            return jsonify({
                "enable": False,
                "request_raw_query": request_raw_query
            }), 200
Ejemplo n.º 4
0
    def report_lifecycle_coreos_install(status, request_raw_query):
        """
        Lifecycle CoreOS Install
        Report the status of a CoreOS install by MAC
        ---
        tags:
          - lifecycle
        responses:
          200:
            description: CoreOS Install report
            schema:
                type: dict
        """
        app.logger.info("%s %s" % (request.method, request.url))
        if status.lower() == "success":
            success = True
        elif status.lower() == "fail":
            success = False
        else:
            app.logger.error("%s %s" % (request.method, request.url))
            return "success or fail != %s" % status.lower(), 403

        with session_commit(sess_maker=sess_maker) as session:
            inject = crud.InjectLifecycle(session,
                                          request_raw_query=request_raw_query)
            inject.refresh_lifecycle_coreos_install(success)

        registry.machine_state.update(
            mac=tools.get_mac_from_raw_query(request_raw_query),
            state=MachineStates.installation_succeed
            if success else MachineStates.installation_failed)
        return jsonify({
            "success": success,
            "request_raw_query": request_raw_query
        }), 200
Ejemplo n.º 5
0
 def test_35(self):
     with session_commit(sess_maker=self.sess_maker) as session:
         rq = "uuid=%s&mac=%s&os=installed" % (
             posts.M03["boot-info"]["uuid"], posts.M03["boot-info"]["mac"])
         i = crud.InjectLifecycle(session, request_raw_query=rq)
         i.refresh_lifecycle_coreos_install(True)
     f = crud.FetchLifecycle(sess_maker=self.sess_maker)
     self.assertTrue(
         f.get_coreos_install_status(posts.M03["boot-info"]["mac"]))
     self.assertEqual(1, len(f.get_all_coreos_install_status()))
Ejemplo n.º 6
0
    def change_lifecycle_rolling(request_raw_query):
        """
        Lifecycle Rolling Update
        Change the current policy for a given machine by MAC
        ---
        tags:
          - lifecycle
        parameters:
          - name: request_raw_query
            in: path
            description: Pass the mac as 'mac=<mac>'
            required: true
            type: string
        responses:
          200:
            description: Rolling Update is enable
            schema:
                type: dict
          401:
            description: Mac address is not in database
            schema:
                type: dict
        """

        app.logger.info("%s %s" % (request.method, request.url))
        try:
            strategy = json.loads(request.get_data())["strategy"]
            app.logger.info("%s %s rolling strategy: setting to %s" %
                            (request.method, request.url, strategy))
        except (KeyError, ValueError):
            # JSONDecodeError is a subclass of ValueError
            # Cannot use JSONDecodeError because the import is not consistent between python3.X
            app.logger.info(
                "%s %s rolling strategy: setting default to kexec" %
                (request.method, request.url))
            strategy = "kexec"

        with session_commit(sess_maker=sess_maker) as session:
            try:
                life = crud.InjectLifecycle(session, request_raw_query)
                life.apply_lifecycle_rolling(True, strategy)
                return jsonify({
                    "enable": True,
                    "request_raw_query": request_raw_query,
                    "strategy": strategy
                }), 200
            except AttributeError:
                return jsonify({
                    "enable": None,
                    "request_raw_query": request_raw_query,
                    "strategy": strategy
                }), 401
Ejemplo n.º 7
0
    def submit_lifecycle_ignition(request_raw_query):
        """
        Lifecycle Ignition
        ---
        tags:
          - lifecycle
        responses:
          200:
            description: A JSON of the ignition status
        """
        try:
            machine_ignition = json.loads(request.get_data())
        except ValueError:
            app.logger.error("%s have incorrect content" % request.path)
            return jsonify({"message": "FlaskValueError"}), 406
        req = requests.get("%s/ignition?%s" %
                           (ec.matchbox_uri, request_raw_query))
        try:
            matchbox_ignition = json.loads(req.content)
            req.close()
        except ValueError:
            app.logger.error("%s have incorrect matchbox return" %
                             request.path)
            return jsonify({"message": "MatchboxValueError"}), 406

        with session_commit(sess_maker=sess_maker) as session:
            try:
                inject = crud.InjectLifecycle(
                    session, request_raw_query=request_raw_query)
                if json.dumps(machine_ignition,
                              sort_keys=True) == json.dumps(matchbox_ignition,
                                                            sort_keys=True):
                    inject.refresh_lifecycle_ignition(True)
                    return jsonify({"message": "Up-to-date"}), 200
                else:
                    inject.refresh_lifecycle_ignition(False)
                    return jsonify({"message": "Outdated"}), 210
            except AttributeError:
                return jsonify({"message": "Unknown"}), 406
Ejemplo n.º 8
0
 def test_32(self):
     with session_commit(sess_maker=self.sess_maker) as session:
         rq = "uuid=%s&mac=%s&os=installed" % (
             posts.M01["boot-info"]["uuid"], posts.M01["boot-info"]["mac"])
         i = crud.InjectLifecycle(session, request_raw_query=rq)
         i.refresh_lifecycle_ignition(True)
Ejemplo n.º 9
0
 def test_31(self):
     with session_commit(sess_maker=self.sess_maker) as session:
         rq = "os=installed"
         with self.assertRaises(AttributeError):
             crud.InjectLifecycle(session, request_raw_query=rq)
Ejemplo n.º 10
0
 def test_30(self):
     with session_commit(sess_maker=self.sess_maker) as session:
         rq = "uuid=%s&mac=%s&os=installed" % (
             posts.M01["boot-info"]["uuid"], posts.M01["boot-info"]["mac"])
         i = crud.InjectLifecycle(session, request_raw_query=rq)
         self.assertEqual(i.mac, posts.M01["boot-info"]["mac"])