Pārlūkot izejas kodu

初步实现启动作业功能

James Iter 9 gadi atpakaļ
vecāks
revīzija
3db7210b5a
8 mainītis faili ar 293 papildinājumiem un 138 dzēšanām
  1. 124 22
      api/guest.py
  2. 18 5
      api/operate_rule.py
  3. 5 3
      api_route_table.py
  4. 1 1
      models/filter.py
  5. 1 1
      models/initialize.py
  6. 104 90
      tests/test_boot_job.py
  7. 25 16
      tests/test_guest.py
  8. 15 0
      tests/test_operate_rule.py

+ 124 - 22
api/guest.py

@@ -131,12 +131,21 @@ def r_create():
             _operate_rules = copy.deepcopy(operate_rules)
             for k, v in enumerate(_operate_rules):
                 _operate_rules[k]['content'] = v['content'].replace('{IP}', guest.ip).\
-                    replace('{HOSTNAME}', guest.name).\
+                    replace('{HOSTNAME}', guest.name). \
+                    replace('{PASSWORD}', guest.password). \
                     replace('{NETMASK}', config.netmask).\
                     replace('{GATEWAY}', config.gateway).\
                     replace('{DNS1}', config.dns1).\
                     replace('{DNS2}', config.dns2)
 
+                _operate_rules[k]['command'] = v['command'].replace('{IP}', guest.ip). \
+                    replace('{HOSTNAME}', guest.name). \
+                    replace('{PASSWORD}', guest.password). \
+                    replace('{NETMASK}', config.netmask). \
+                    replace('{GATEWAY}', config.gateway). \
+                    replace('{DNS1}', config.dns1). \
+                    replace('{DNS2}', config.dns2)
+
             create_vm_msg = {
                 'action': 'create_guest',
                 'uuid': guest.uuid,
@@ -280,8 +289,38 @@ def r_boot(uuids):
             guest.uuid = uuid
             guest.get_by('uuid')
 
+        config = Config()
+        config.id = 1
+        config.get()
+
         for uuid in uuids.split(','):
-            message = {'action': 'boot', 'uuid': uuid}
+            boot_jobs_id = guest.get_boot_jobs()
+
+            boot_jobs = list()
+
+            if boot_jobs_id.__len__() > 0:
+                boot_jobs, count = OperateRule.get_by_filter(filter_str='boot_job_id:in:' + ','.join(boot_jobs_id))
+
+            # 替换占位符为有效内容
+            for k, v in enumerate(boot_jobs):
+                boot_jobs[k]['content'] = v['content'].replace('{IP}', guest.ip). \
+                    replace('{HOSTNAME}', guest.name). \
+                    replace('{PASSWORD}', guest.password). \
+                    replace('{NETMASK}', config.netmask). \
+                    replace('{GATEWAY}', config.gateway). \
+                    replace('{DNS1}', config.dns1). \
+                    replace('{DNS2}', config.dns2)
+
+                boot_jobs[k]['command'] = v['command'].replace('{IP}', guest.ip). \
+                    replace('{HOSTNAME}', guest.name). \
+                    replace('{PASSWORD}', guest.password). \
+                    replace('{NETMASK}', config.netmask). \
+                    replace('{GATEWAY}', config.gateway). \
+                    replace('{DNS1}', config.dns1). \
+                    replace('{DNS2}', config.dns2)
+
+            message = {'action': 'boot', 'uuid': uuid, 'boot_jobs': boot_jobs,
+                       'passback_parameters': {'boot_jobs_id': boot_jobs_id}}
             Guest.emit_instruction(message=json.dumps(message))
 
         ret = dict()
@@ -577,25 +616,38 @@ def r_update(uuid):
 
 
 @Utils.dumps2response
-def r_add_boot_jobs(uuid, boot_jobs_id):
+def r_add_boot_jobs(uuids, boot_jobs_id):
 
     args_rules = [
-        Rules.UUID.value,
+        Rules.UUIDS.value,
         Rules.BOOT_JOBS_ID.value
     ]
 
     try:
-        ji.Check.previewing(args_rules, {'uuid': uuid, 'boot_jobs_id': boot_jobs_id})
+        ji.Check.previewing(args_rules, {'uuids': uuids, 'boot_jobs_id': boot_jobs_id})
 
         guest = Guest()
-        guest.uuid = uuid
-        guest.get_by('uuid')
+        for uuid in uuids.split(','):
+            guest.uuid = uuid
+            guest.get_by('uuid')
 
-        guest.add_boot_jobs(boot_jobs_id=boot_jobs_id.split(','))
+        for uuid in uuids.split(','):
+            guest.uuid = uuid
+            guest.add_boot_jobs(boot_jobs_id=boot_jobs_id.split(','))
 
         ret = dict()
         ret['state'] = ji.Common.exchange_state(20000)
-        ret['data'] = guest.get_boot_jobs()
+
+        if uuids.split(',').__len__() > 1:
+            ret['data'] = dict()
+            for uuid in uuids.split(','):
+                guest.uuid = uuid
+                ret['data'][uuid] = guest.get_boot_jobs()
+
+        else:
+            guest.uuid = uuids
+            ret['data'] = guest.get_boot_jobs()
+
         return ret
 
     except ji.PreviewingError, e:
@@ -603,21 +655,34 @@ def r_add_boot_jobs(uuid, boot_jobs_id):
 
 
 @Utils.dumps2response
-def r_get_boot_jobs(uuid):
+def r_get_boot_jobs(uuids):
 
     args_rules = [
-        Rules.UUID.value
+        Rules.UUIDS.value
     ]
 
     try:
-        ji.Check.previewing(args_rules, {'uuid': uuid})
+        ji.Check.previewing(args_rules, {'uuids': uuids})
+
         guest = Guest()
-        guest.uuid = uuid
-        guest.get_by('uuid')
+
+        for uuid in uuids.split(','):
+            guest.uuid = uuid
+            guest.get_by('uuid')
 
         ret = dict()
         ret['state'] = ji.Common.exchange_state(20000)
-        ret['data'] = guest.get_boot_jobs()
+
+        if uuids.split(',').__len__() > 1:
+            ret['data'] = dict()
+            for uuid in uuids.split(','):
+                guest.uuid = uuid
+                ret['data'][uuid] = guest.get_boot_jobs()
+
+        else:
+            guest.uuid = uuids
+            ret['data'] = guest.get_boot_jobs()
+
         return ret
 
     except ji.PreviewingError, e:
@@ -625,25 +690,62 @@ def r_get_boot_jobs(uuid):
 
 
 @Utils.dumps2response
-def r_delete_boot_jobs(uuid, boot_jobs_id):
+def r_delete_boot_jobs(uuids, boot_jobs_id):
 
     args_rules = [
-        Rules.UUID.value,
+        Rules.UUIDS.value,
         Rules.BOOT_JOBS_ID.value
     ]
 
     try:
-        ji.Check.previewing(args_rules, {'uuid': uuid, 'boot_jobs_id': boot_jobs_id})
+        ji.Check.previewing(args_rules, {'uuids': uuids, 'boot_jobs_id': boot_jobs_id})
 
         guest = Guest()
-        guest.uuid = uuid
-        guest.get_by('uuid')
+        # 检测所指定的 UUDIs 实例都存在
+        for uuid in uuids.split(','):
+            guest.uuid = uuid
+            guest.get_by('uuid')
+
+        for uuid in uuids.split(','):
+            guest.uuid = uuid
+            guest.delete_boot_jobs(boot_jobs_id=boot_jobs_id.split(','))
+
+        ret = dict()
+        ret['state'] = ji.Common.exchange_state(20000)
+        return ret
+
+    except ji.PreviewingError, e:
+        return json.loads(e.message)
+
+
+@Utils.dumps2response
+def r_reset_password(uuids, password):
+
+    args_rules = [
+        Rules.UUIDS.value,
+        Rules.PASSWORD.value
+    ]
+
+    try:
+        ji.Check.previewing(args_rules, {'uuids': uuids, 'password': password})
+
+        guest = Guest()
+        # 检测所指定的 UUDIs 实例都存在
+        for uuid in uuids.split(','):
+            guest.uuid = uuid
+            guest.get_by('uuid')
+
+        # 重置密码的 boot job id 固定为 1
+        for uuid in uuids.split(','):
+            guest.uuid = uuid
+            guest.get_by('uuid')
+            guest.password = password
+            guest.update()
 
-        guest.delete_boot_jobs(boot_jobs_id=boot_jobs_id.split(','))
+            guest.add_boot_jobs(boot_jobs_id=['1'])
 
         ret = dict()
         ret['state'] = ji.Common.exchange_state(20000)
-        ret['data'] = guest.get_boot_jobs()
         return ret
 
     except ji.PreviewingError, e:

+ 18 - 5
api/operate_rule.py

@@ -77,14 +77,27 @@ def r_create():
             ret['state']['sub']['zh-cn'] = ''.join([ret['state']['sub']['zh-cn'], ': ', boot_job.id.__str__()])
             return ret
 
-        data, total = operate_rule.get_by_filter(
-            filter_str=':'.join(['boot_job_id', 'eq', operate_rule.boot_job_id.__str__()]) + ';' +
-                       ':'.join(['path', 'eq', operate_rule.path]))
+        if operate_rule.kind == OperateRuleKind.cmd.value:
+            data, total = operate_rule.get_by_filter(
+                filter_str=':'.join(['boot_job_id', 'eq', operate_rule.boot_job_id.__str__()]) + ';' +
+                           ':'.join(['command', 'eq', operate_rule.command]))
+
+        else:
+            data, total = operate_rule.get_by_filter(
+                filter_str=':'.join(['boot_job_id', 'eq', operate_rule.boot_job_id.__str__()]) + ';' +
+                           ':'.join(['path', 'eq', operate_rule.path]))
 
         if data.__len__() > 0:
             ret['state'] = ji.Common.exchange_state(40901)
-            ret['state']['sub']['zh-cn'] = ''.join([ret['state']['sub']['zh-cn'], ', path: ', operate_rule.path,
-                                                    ', boot_job_id: ', operate_rule.boot_job_id.__str__()])
+
+            if operate_rule.kind == OperateRuleKind.cmd.value:
+                ret['state']['sub']['zh-cn'] = ''.join([ret['state']['sub']['zh-cn'],
+                                                        ', command: ', operate_rule.command,
+                                                        ', boot_job_id: ', operate_rule.boot_job_id.__str__()])
+
+            else:
+                ret['state']['sub']['zh-cn'] = ''.join([ret['state']['sub']['zh-cn'], ', path: ', operate_rule.path,
+                                                        ', boot_job_id: ', operate_rule.boot_job_id.__str__()])
             return ret
 
         operate_rule.create()

+ 5 - 3
api_route_table.py

@@ -66,10 +66,12 @@ add_rule_api(guest.blueprints, '', api_func='guest.r_get_by_filter', methods=['G
 add_rule_api(guest.blueprints, '/_search', api_func='guest.r_content_search', methods=['GET'])
 add_rule_api(guest.blueprint, '/<uuid>', api_func='guest.r_update', methods=['PATCH'])
 add_rule_api(guest.blueprints, '/<uuids>', api_func='guest.r_delete', methods=['DELETE'])
-add_rule_api(guest.blueprint, '/_boot_jobs/<uuid>/<boot_jobs_id>', api_func='guest.r_add_boot_jobs', methods=['PUT'])
-add_rule_api(guest.blueprint, '/_boot_jobs/<uuid>', api_func='guest.r_get_boot_jobs', methods=['GET'])
-add_rule_api(guest.blueprint, '/_boot_jobs/<uuid>/<boot_jobs_id>', api_func='guest.r_delete_boot_jobs',
+add_rule_api(guest.blueprints, '/_boot_jobs/<uuids>/<boot_jobs_id>', api_func='guest.r_add_boot_jobs', methods=['PUT'])
+add_rule_api(guest.blueprints, '/_boot_jobs/<uuids>', api_func='guest.r_get_boot_jobs', methods=['GET'])
+add_rule_api(guest.blueprints, '/_boot_jobs/<uuids>/<boot_jobs_id>', api_func='guest.r_delete_boot_jobs',
              methods=['DELETE'])
+add_rule_api(guest.blueprints, '/_reset_password/<uuids>/<password>', api_func='guest.r_reset_password',
+             methods=['PUT'])
 
 # Disk操作
 add_rule_api(disk.blueprint, '', api_func='disk.r_create', methods=['POST'])

+ 1 - 1
models/filter.py

@@ -52,7 +52,7 @@ class Filter(object):
         if regex_dsl_str.match(dsl) is None:
             return sql_stmt
 
-        keyword, operator, value = dsl.split(':')
+        keyword, operator, value = dsl.split(':', 2)
         operator = operator.lower()
 
         if keyword not in allow_keywords.keys():

+ 1 - 1
models/initialize.py

@@ -96,7 +96,7 @@ class Init(object):
 q_ws = JoinableQueue()
 # 预编译效率更高
 regex_sql_str = re.compile('\\\+"')
-regex_dsl_str = re.compile('^\w+:\w+:\S+$')
+regex_dsl_str = re.compile('^\w+:\w+:[\S| ]+$')
 
 config = Init.load_config()
 logger = Init.init_logger()

+ 104 - 90
tests/test_boot_job.py

@@ -24,53 +24,53 @@ class TestOSInit(unittest.TestCase):
     def tearDown(self):
         pass
 
-    # 创建系统初始化组
-    def test_11_create(self):
-        payload = {
-            "name": 'CentOS-Systemd',
-            "use_for": 0,
-            "remark": u'用作红帽 Systemd 系列的系统初始化。初始化操作依据 CentOS 7 来实现。'
-        }
-
-        url = TestOSInit.base_url + '/boot_job'
-        headers = {'content-type': 'application/json'}
-        r = requests.post(url, data=json.dumps(payload), headers=headers)
-        j_r = json.loads(r.content)
-        print json.dumps(j_r, ensure_ascii=False)
-        self.assertEqual('200', j_r['state']['code'])
-
-    # 获取系统初始化组列表
-    def test_12_get(self):
-        url = TestOSInit.base_url + '/boot_jobs'
-        headers = {'content-type': 'application/json'}
-        r = requests.get(url, headers=headers)
-        j_r = json.loads(r.content)
-        print json.dumps(j_r, ensure_ascii=False)
-        TestOSInit.boot_job_id = j_r['data'][0]['id']
-        self.assertEqual('200', j_r['state']['code'])
-
-    # 创建更新系统初始化组
-    def test_13_update(self):
-        payload = {
-            "name": 'RedHat-Systemd'
-        }
-
-        url = TestOSInit.base_url + '/boot_job/' + TestOSInit.boot_job_id.__str__()
-        headers = {'content-type': 'application/json'}
-        r = requests.patch(url, data=json.dumps(payload), headers=headers)
-        j_r = json.loads(r.content)
-        print json.dumps(j_r, ensure_ascii=False)
-        self.assertEqual('200', j_r['state']['code'])
-
-    # 校验系统初始化组列表更新结果
-    def test_14_get(self):
-        url = TestOSInit.base_url + '/boot_jobs'
-        headers = {'content-type': 'application/json'}
-        r = requests.get(url, headers=headers)
-        j_r = json.loads(r.content)
-        print json.dumps(j_r, ensure_ascii=False)
-        self.assertEqual('200', j_r['state']['code'])
-        self.assertEqual('RedHat-Systemd', j_r['data'][0]['name'])
+    # # 创建系统初始化组
+    # def test_11_create(self):
+    #     payload = {
+    #         "name": 'CentOS-Systemd',
+    #         "use_for": 0,
+    #         "remark": u'用作红帽 Systemd 系列的系统初始化。初始化操作依据 CentOS 7 来实现。'
+    #     }
+    #
+    #     url = TestOSInit.base_url + '/boot_job'
+    #     headers = {'content-type': 'application/json'}
+    #     r = requests.post(url, data=json.dumps(payload), headers=headers)
+    #     j_r = json.loads(r.content)
+    #     print json.dumps(j_r, ensure_ascii=False)
+    #     self.assertEqual('200', j_r['state']['code'])
+    #
+    # # 获取系统初始化组列表
+    # def test_12_get(self):
+    #     url = TestOSInit.base_url + '/boot_jobs'
+    #     headers = {'content-type': 'application/json'}
+    #     r = requests.get(url, headers=headers)
+    #     j_r = json.loads(r.content)
+    #     print json.dumps(j_r, ensure_ascii=False)
+    #     TestOSInit.boot_job_id = j_r['data'][0]['id']
+    #     self.assertEqual('200', j_r['state']['code'])
+    #
+    # # 创建更新系统初始化组
+    # def test_13_update(self):
+    #     payload = {
+    #         "name": 'RedHat-Systemd'
+    #     }
+    #
+    #     url = TestOSInit.base_url + '/boot_job/' + TestOSInit.boot_job_id.__str__()
+    #     headers = {'content-type': 'application/json'}
+    #     r = requests.patch(url, data=json.dumps(payload), headers=headers)
+    #     j_r = json.loads(r.content)
+    #     print json.dumps(j_r, ensure_ascii=False)
+    #     self.assertEqual('200', j_r['state']['code'])
+    #
+    # # 校验系统初始化组列表更新结果
+    # def test_14_get(self):
+    #     url = TestOSInit.base_url + '/boot_jobs'
+    #     headers = {'content-type': 'application/json'}
+    #     r = requests.get(url, headers=headers)
+    #     j_r = json.loads(r.content)
+    #     print json.dumps(j_r, ensure_ascii=False)
+    #     self.assertEqual('200', j_r['state']['code'])
+    #     self.assertEqual('RedHat-Systemd', j_r['data'][0]['name'])
 
     # # 删除系统初始化组列表更新结果
     # def test_15_delete(self):
@@ -81,49 +81,63 @@ class TestOSInit(unittest.TestCase):
     #     print json.dumps(j_r, ensure_ascii=False)
     #     self.assertEqual('200', j_r['state']['code'])
 
-    def test_21_create(self):
-        payload = {
-            "name": 'Gentoo-OpenRC',
-            "use_for": 0,
-            "remark": u'Gentoo startup process。'
-        }
-
-        url = TestOSInit.base_url + '/boot_job'
-        headers = {'content-type': 'application/json'}
-        r = requests.post(url, data=json.dumps(payload), headers=headers)
-        j_r = json.loads(r.content)
-        print json.dumps(j_r, ensure_ascii=False)
-        self.assertEqual('200', j_r['state']['code'])
-
-    # 创建系统初始化组
-    def test_22_create(self):
-        payload = {
-            "name": 'Ubuntu-Upstart',
-            "use_for": 0,
-            "remark": u'Ubuntu startup process。'
-        }
-
-        url = TestOSInit.base_url + '/boot_job'
-        headers = {'content-type': 'application/json'}
-        r = requests.post(url, data=json.dumps(payload), headers=headers)
-        j_r = json.loads(r.content)
-        print json.dumps(j_r, ensure_ascii=False)
-        self.assertEqual('200', j_r['state']['code'])
-
-    # 创建系统初始化组
-    def test_23_create(self):
-        payload = {
-            "name": 'CentOS-SysV',
-            "use_for": 0,
-            "remark": u'用作CentOS SysV 系列的系统初始化。初始化操作依据 CentOS 6.8 来实现。'
-        }
-
-        url = TestOSInit.base_url + '/boot_job'
-        headers = {'content-type': 'application/json'}
-        r = requests.post(url, data=json.dumps(payload), headers=headers)
-        j_r = json.loads(r.content)
-        print json.dumps(j_r, ensure_ascii=False)
-        self.assertEqual('200', j_r['state']['code'])
+    # def test_21_create(self):
+    #     payload = {
+    #         "name": 'Gentoo-OpenRC',
+    #         "use_for": 0,
+    #         "remark": u'Gentoo startup process。'
+    #     }
+    #
+    #     url = TestOSInit.base_url + '/boot_job'
+    #     headers = {'content-type': 'application/json'}
+    #     r = requests.post(url, data=json.dumps(payload), headers=headers)
+    #     j_r = json.loads(r.content)
+    #     print json.dumps(j_r, ensure_ascii=False)
+    #     self.assertEqual('200', j_r['state']['code'])
+    #
+    # # 创建系统初始化组
+    # def test_22_create(self):
+    #     payload = {
+    #         "name": 'Ubuntu-Upstart',
+    #         "use_for": 0,
+    #         "remark": u'Ubuntu startup process。'
+    #     }
+    #
+    #     url = TestOSInit.base_url + '/boot_job'
+    #     headers = {'content-type': 'application/json'}
+    #     r = requests.post(url, data=json.dumps(payload), headers=headers)
+    #     j_r = json.loads(r.content)
+    #     print json.dumps(j_r, ensure_ascii=False)
+    #     self.assertEqual('200', j_r['state']['code'])
+    #
+    # # 创建系统初始化组
+    # def test_23_create(self):
+    #     payload = {
+    #         "name": 'CentOS-SysV',
+    #         "use_for": 0,
+    #         "remark": u'用作CentOS SysV 系列的系统初始化。初始化操作依据 CentOS 6.8 来实现。'
+    #     }
+    #
+    #     url = TestOSInit.base_url + '/boot_job'
+    #     headers = {'content-type': 'application/json'}
+    #     r = requests.post(url, data=json.dumps(payload), headers=headers)
+    #     j_r = json.loads(r.content)
+    #     print json.dumps(j_r, ensure_ascii=False)
+    #     self.assertEqual('200', j_r['state']['code'])
+    #
+    # def test_24_create(self):
+    #     payload = {
+    #         "name": 'Reset password for Linux',
+    #         "use_for": 1,
+    #         "remark": u'重置 Linux 平台管理员密码。'
+    #     }
+    #
+    #     url = TestOSInit.base_url + '/boot_job'
+    #     headers = {'content-type': 'application/json'}
+    #     r = requests.post(url, data=json.dumps(payload), headers=headers)
+    #     j_r = json.loads(r.content)
+    #     print json.dumps(j_r, ensure_ascii=False)
+    #     self.assertEqual('200', j_r['state']['code'])
 
 if __name__ == '__main__':
     unittest.main()

+ 25 - 16
tests/test_guest.py

@@ -254,26 +254,26 @@ class TestGuest(unittest.TestCase):
     #     self.assertEqual('200', j_r['state']['code'])
 
     # def test_71_add_boot_jobs_id(self):
-    #     TestGuest.uuid = 'ba38a067-83cb-49e8-bfc1-7dce7d5e34e6'
-    #     url = TestGuest.base_url + '/guest/_boot_jobs/' + TestGuest.uuid + '/' + '1,2,4'
+    #     TestGuest.uuid = 'ba38a067-83cb-49e8-bfc1-7dce7d5e34e6,5fdfe92a-b2dd-4fcf-8be5-06b185212e70'
+    #     url = TestGuest.base_url + '/guests/_boot_jobs/' + TestGuest.uuid + '/' + '1,2,4'
     #     headers = {'content-type': 'application/json'}
     #     r = requests.put(url, headers=headers)
     #     j_r = json.loads(r.content)
     #     print json.dumps(j_r, ensure_ascii=False)
     #     self.assertEqual('200', j_r['state']['code'])
-
-    def test_72_get_boot_jobs_id(self):
-        TestGuest.uuid = 'ba38a067-83cb-49e8-bfc1-7dce7d5e34e6'
-        url = TestGuest.base_url + '/guest/_boot_jobs/' + TestGuest.uuid
-        headers = {'content-type': 'application/json'}
-        r = requests.get(url, headers=headers)
-        j_r = json.loads(r.content)
-        print json.dumps(j_r, ensure_ascii=False)
-        self.assertEqual('200', j_r['state']['code'])
-
+    #
+    # def test_72_get_boot_jobs_id(self):
+    #     TestGuest.uuid = 'ba38a067-83cb-49e8-bfc1-7dce7d5e34e6,5fdfe92a-b2dd-4fcf-8be5-06b185212e70'
+    #     url = TestGuest.base_url + '/guests/_boot_jobs/' + TestGuest.uuid
+    #     headers = {'content-type': 'application/json'}
+    #     r = requests.get(url, headers=headers)
+    #     j_r = json.loads(r.content)
+    #     print json.dumps(j_r, ensure_ascii=False)
+    #     self.assertEqual('200', j_r['state']['code'])
+    #
     # def test_73_delete_boot_jobs_id(self):
-    #     TestGuest.uuid = 'ba38a067-83cb-49e8-bfc1-7dce7d5e34e6'
-    #     url = TestGuest.base_url + '/guest/_boot_jobs/' + TestGuest.uuid + '/' + '1,2,3'
+    #     TestGuest.uuid = 'ba38a067-83cb-49e8-bfc1-7dce7d5e34e6,5fdfe92a-b2dd-4fcf-8be5-06b185212e70'
+    #     url = TestGuest.base_url + '/guests/_boot_jobs/' + TestGuest.uuid + '/' + '1,2,3'
     #     headers = {'content-type': 'application/json'}
     #     r = requests.delete(url, headers=headers)
     #     j_r = json.loads(r.content)
@@ -281,13 +281,22 @@ class TestGuest(unittest.TestCase):
     #     self.assertEqual('200', j_r['state']['code'])
     #
     # def test_74_delete_boot_jobs_id(self):
-    #     TestGuest.uuid = 'ba38a067-83cb-49e8-bfc1-7dce7d5e34e6'
-    #     url = TestGuest.base_url + '/guest/_boot_jobs/' + TestGuest.uuid + '/' + '4'
+    #     TestGuest.uuid = 'ba38a067-83cb-49e8-bfc1-7dce7d5e34e6,5fdfe92a-b2dd-4fcf-8be5-06b185212e70'
+    #     url = TestGuest.base_url + '/guests/_boot_jobs/' + TestGuest.uuid + '/' + '4'
     #     headers = {'content-type': 'application/json'}
     #     r = requests.delete(url, headers=headers)
     #     j_r = json.loads(r.content)
     #     print json.dumps(j_r, ensure_ascii=False)
     #     self.assertEqual('200', j_r['state']['code'])
+    #
+    def test_81_reset_password(self):
+        TestGuest.uuid = 'ba38a067-83cb-49e8-bfc1-7dce7d5e34e6,5fdfe92a-b2dd-4fcf-8be5-06b185212e70'
+        url = TestGuest.base_url + '/guests/_reset_password/' + TestGuest.uuid + '/' + 'new.pswd.com'
+        headers = {'content-type': 'application/json'}
+        r = requests.put(url, headers=headers)
+        j_r = json.loads(r.content)
+        print json.dumps(j_r, ensure_ascii=False)
+        self.assertEqual('200', j_r['state']['code'])
 
 if __name__ == '__main__':
     unittest.main()

+ 15 - 0
tests/test_operate_rule.py

@@ -259,6 +259,21 @@ class TestOperateRule(unittest.TestCase):
     #     TestOperateRule.operate_rule_id = j_r['data']['id']
     #     self.assertEqual('200', j_r['state']['code'])
 
+    # def test_64_create(self):
+    #     payload = {
+    #         "boot_job_id": 1,
+    #         "kind": 0,
+    #         "command": "echo \"root:{PASSWORD}\" | chpasswd"
+    #     }
+    #
+    #     url = TestOperateRule.base_url + '/operate_rule'
+    #     headers = {'content-type': 'application/json'}
+    #     r = requests.post(url, data=json.dumps(payload), headers=headers)
+    #     j_r = json.loads(r.content)
+    #     print json.dumps(j_r, ensure_ascii=False)
+    #     TestOperateRule.operate_rule_id = j_r['data']['id']
+    #     self.assertEqual('200', j_r['state']['code'])
+
 if __name__ == '__main__':
     unittest.main()