test_os_init_write.py 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import requests
  4. import json
  5. import unittest
  6. __author__ = 'James Iter'
  7. __date__ = '2017/3/31'
  8. __contact__ = 'james.iter.cn@gmail.com'
  9. __copyright__ = '(c) 2017 by James Iter.'
  10. class TestOSInitWrite(unittest.TestCase):
  11. base_url = 'http://127.0.0.1:8008/api'
  12. os_init_id = 3
  13. os_init_write_id = 0
  14. def setUp(self):
  15. pass
  16. def tearDown(self):
  17. pass
  18. # # 创建系统初始化组
  19. # def test_11_create(self):
  20. # payload = {
  21. # "name": "CentOS-Systemd",
  22. # "remark": u"用作红帽 Systemd 系列的系统初始化。初始化操作依据 CentOS 7 来实现。"
  23. # }
  24. #
  25. # url = TestOSInitWrite.base_url + '/os_init'
  26. # headers = {'content-type': 'application/json'}
  27. # r = requests.post(url, data=json.dumps(payload), headers=headers)
  28. # j_r = json.loads(r.content)
  29. # print json.dumps(j_r, ensure_ascii=False)
  30. # TestOSInitWrite.os_init_id = j_r['data']['id']
  31. # self.assertEqual('200', j_r['state']['code'])
  32. #
  33. # # 添加系统初始化操作
  34. # def test_21_create(self):
  35. # payload = {
  36. # "os_init_id": TestOSInitWrite.os_init_id,
  37. # "path": "/etc/resolv.conf",
  38. # "content": "\n".join([
  39. # "nameserver {DNS1}",
  40. # "nameserver {DNS2}"
  41. # ])
  42. # }
  43. #
  44. # url = TestOSInitWrite.base_url + '/os_init_write'
  45. # headers = {'content-type': 'application/json'}
  46. # r = requests.post(url, data=json.dumps(payload), headers=headers)
  47. # j_r = json.loads(r.content)
  48. # print json.dumps(j_r, ensure_ascii=False)
  49. # self.assertEqual('200', j_r['state']['code'])
  50. #
  51. # # 添加系统初始化操作
  52. # def test_22_create(self):
  53. # payload = {
  54. # "os_init_id": TestOSInitWrite.os_init_id,
  55. # "path": "/etc/sysconfig/network-scripts/ifcfg-eth0",
  56. # "content": "\n".join([
  57. # "DEVICE=eth0",
  58. # "TYPE=Ethernet",
  59. # "ONBOOT=yes",
  60. # "BOOTPROTO=\"static\"",
  61. # "IPADDR={IP}",
  62. # "NETMASK={NETMASK}",
  63. # "GATEWAY={GATEWAY}",
  64. # "DNS1={DNS1}",
  65. # "DNS2={DNS2}",
  66. # "IPV6INIT=no",
  67. # "NAME=eth0"
  68. # ])
  69. # }
  70. #
  71. # url = TestOSInitWrite.base_url + '/os_init_write'
  72. # headers = {'content-type': 'application/json'}
  73. # r = requests.post(url, data=json.dumps(payload), headers=headers)
  74. # j_r = json.loads(r.content)
  75. # print json.dumps(j_r, ensure_ascii=False)
  76. # self.assertEqual('200', j_r['state']['code'])
  77. #
  78. # # 添加系统初始化操作
  79. # def test_23_create(self):
  80. # payload = {
  81. # "os_init_id": TestOSInitWrite.os_init_id,
  82. # "path": "/etc/hostname",
  83. # "content": "hostname"
  84. # }
  85. #
  86. # url = TestOSInitWrite.base_url + '/os_init_write'
  87. # headers = {'content-type': 'application/json'}
  88. # r = requests.post(url, data=json.dumps(payload), headers=headers)
  89. # j_r = json.loads(r.content)
  90. # print json.dumps(j_r, ensure_ascii=False)
  91. # TestOSInitWrite.os_init_write_id = j_r['data']['id']
  92. # self.assertEqual('200', j_r['state']['code'])
  93. #
  94. # def test_25_get_list(self):
  95. # url = TestOSInitWrite.base_url + '/os_init_writes'
  96. # headers = {'content-type': 'application/json'}
  97. # r = requests.get(url, headers=headers)
  98. # j_r = json.loads(r.content)
  99. # print json.dumps(j_r, ensure_ascii=False)
  100. # self.assertEqual('200', j_r['state']['code'])
  101. #
  102. # def test_26_update(self):
  103. # payload = {
  104. # "path": "/etc/hostname",
  105. # "content": "{HOSTNAME}"
  106. # }
  107. #
  108. # url = TestOSInitWrite.base_url + '/os_init_write/' + TestOSInitWrite.os_init_write_id.__str__()
  109. # headers = {'content-type': 'application/json'}
  110. # r = requests.patch(url, data=json.dumps(payload), headers=headers)
  111. # j_r = json.loads(r.content)
  112. # print json.dumps(j_r, ensure_ascii=False)
  113. # self.assertEqual('200', j_r['state']['code'])
  114. #
  115. # @unittest.skip('skip delete os init write!')
  116. # def test_27_delete(self):
  117. # url = TestOSInitWrite.base_url + '/os_init_writes/' + TestOSInitWrite.os_init_write_id.__str__()
  118. # headers = {'content-type': 'application/json'}
  119. # r = requests.delete(url, headers=headers)
  120. # j_r = json.loads(r.content)
  121. # print json.dumps(j_r, ensure_ascii=False)
  122. # self.assertEqual('200', j_r['state']['code'])
  123. #
  124. # @unittest.skip('skip delete os init!')
  125. # # 删除系统初始化组列表更新结果
  126. # def test_31_delete(self):
  127. # url = TestOSInitWrite.base_url + '/os_init/' + TestOSInitWrite.os_init_id.__str__()
  128. # headers = {'content-type': 'application/json'}
  129. # r = requests.delete(url, headers=headers)
  130. # j_r = json.loads(r.content)
  131. # print json.dumps(j_r, ensure_ascii=False)
  132. # self.assertEqual('200', j_r['state']['code'])
  133. #
  134. # def test_51_create(self):
  135. # payload = {
  136. # "os_init_id": 8,
  137. # "path": "/etc/resolv.conf",
  138. # "content": "\n".join([
  139. # "nameserver {DNS1}",
  140. # "nameserver {DNS2}"
  141. # ])
  142. # }
  143. #
  144. # url = TestOSInitWrite.base_url + '/os_init_write'
  145. # headers = {'content-type': 'application/json'}
  146. # r = requests.post(url, data=json.dumps(payload), headers=headers)
  147. # j_r = json.loads(r.content)
  148. # print json.dumps(j_r, ensure_ascii=False)
  149. # self.assertEqual('200', j_r['state']['code'])
  150. #
  151. # def test_52_create(self):
  152. # payload = {
  153. # "os_init_id": 8,
  154. # "path": "/etc/sysconfig/network-scripts/ifcfg-eth0",
  155. # "content": "\n".join([
  156. # "DEVICE=eth0",
  157. # "TYPE=Ethernet",
  158. # "ONBOOT=yes",
  159. # "BOOTPROTO=\"static\"",
  160. # "IPADDR={IP}",
  161. # "NETMASK={NETMASK}",
  162. # "GATEWAY={GATEWAY}",
  163. # "IPV6INIT=no",
  164. # "NAME=eth0"
  165. # ])
  166. # }
  167. #
  168. # url = TestOSInitWrite.base_url + '/os_init_write'
  169. # headers = {'content-type': 'application/json'}
  170. # r = requests.post(url, data=json.dumps(payload), headers=headers)
  171. # j_r = json.loads(r.content)
  172. # print json.dumps(j_r, ensure_ascii=False)
  173. # self.assertEqual('200', j_r['state']['code'])
  174. #
  175. # def test_53_create(self):
  176. # payload = {
  177. # "os_init_id": 8,
  178. # "path": "/etc/hostname",
  179. # "content": "hostname=\"{HOSTNAME}\""
  180. # }
  181. #
  182. # url = TestOSInitWrite.base_url + '/os_init_write'
  183. # headers = {'content-type': 'application/json'}
  184. # r = requests.post(url, data=json.dumps(payload), headers=headers)
  185. # j_r = json.loads(r.content)
  186. # print json.dumps(j_r, ensure_ascii=False)
  187. # TestOSInitWrite.os_init_write_id = j_r['data']['id']
  188. # self.assertEqual('200', j_r['state']['code'])
  189. #
  190. # def test_61_create(self):
  191. # payload = {
  192. # "os_init_id": 7,
  193. # "path": "/etc/resolv.conf",
  194. # "content": "\n".join([
  195. # "nameserver {DNS1}",
  196. # "nameserver {DNS2}"
  197. # ])
  198. # }
  199. #
  200. # url = TestOSInitWrite.base_url + '/os_init_write'
  201. # headers = {'content-type': 'application/json'}
  202. # r = requests.post(url, data=json.dumps(payload), headers=headers)
  203. # j_r = json.loads(r.content)
  204. # print json.dumps(j_r, ensure_ascii=False)
  205. # self.assertEqual('200', j_r['state']['code'])
  206. #
  207. # def test_62_create(self):
  208. # payload = {
  209. # "os_init_id": 7,
  210. # "path": "/etc/conf.d/net",
  211. # "content": "\n".join([
  212. # "config_eth0=\"{IP}/{NETMASK}\"",
  213. # "routes_eth0=\"default via {GATEWAY}\""
  214. # ])
  215. # }
  216. #
  217. # url = TestOSInitWrite.base_url + '/os_init_write'
  218. # headers = {'content-type': 'application/json'}
  219. # r = requests.post(url, data=json.dumps(payload), headers=headers)
  220. # j_r = json.loads(r.content)
  221. # print json.dumps(j_r, ensure_ascii=False)
  222. # self.assertEqual('200', j_r['state']['code'])
  223. #
  224. # def test_63_create(self):
  225. # payload = {
  226. # "os_init_id": 7,
  227. # "path": "/etc/conf.d/hostname",
  228. # "content": "{HOSTNAME}"
  229. # }
  230. #
  231. # url = TestOSInitWrite.base_url + '/os_init_write'
  232. # headers = {'content-type': 'application/json'}
  233. # r = requests.post(url, data=json.dumps(payload), headers=headers)
  234. # j_r = json.loads(r.content)
  235. # print json.dumps(j_r, ensure_ascii=False)
  236. # TestOSInitWrite.os_init_write_id = j_r['data']['id']
  237. # self.assertEqual('200', j_r['state']['code'])
  238. if __name__ == '__main__':
  239. unittest.main()