Advertisement
ducnv95

test-migrator.py

Sep 7th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 23.49 KB | None | 0 0
  1. # Copyright 2018 Fujitsu Corporation
  2. #
  3. #    Licensed under the Apache License, Version 2.0 (the "License"); you may
  4. #    not use this file except in compliance with the License. You may obtain
  5. #    a copy of the License at
  6. #
  7. #         http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. #    Unless required by applicable law or agreed to in writing, software
  10. #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  11. #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  12. #    License for the specific language governing permissions and limitations
  13. #    under the License.
  14.  
  15. import fixtures
  16. import mock
  17. from oslotest import base
  18. import testscenarios
  19.  
  20. from oslo_config import cfg
  21. from oslo_config import fixture as config_fixture
  22. from oslo_config import generator
  23. from oslo_config import migrator
  24.  
  25. load_tests = testscenarios.load_tests_apply_scenarios
  26.  
  27. scenario_1 = {
  28.     'name': 'scenario 1',
  29.     'purpose': '''
  30.  
  31. This scenario is to migrate old config to new config that there are not
  32. any option deprecated by new options.
  33.  
  34. ''',
  35.     'old_content_file': '''[DEFAULT]
  36. foo_default = value_foo
  37. number1 = 10
  38.  
  39. [group1]
  40. bar_group1 = value_bar
  41. number2 = 20
  42.  
  43. ''',
  44.     'expected': '''[DEFAULT]
  45.  
  46. # Lists configuration groups that provide more details for accessing
  47. # configuration settings from locations other than local files. (list
  48. # value)
  49. config_source =
  50.  
  51. # foo option in DEFAULT section (string value)
  52. foo_default = value_foo
  53.  
  54. # number1 option (integer value)
  55. number1 = 10
  56.  
  57. [group1]
  58.  
  59. # bar option in group1 section (string value)
  60. bar_group1 = value_bar
  61.  
  62. # number2 option (integer value)
  63. number2 = 20
  64. '''
  65. }
  66.  
  67. scenario_2 = {
  68.     'name': 'scenario 2',
  69.     'purpose': '''
  70.  
  71. "deprecated_coo_default" option in DEFAULT section which will be
  72. deprecated in new release and it is replaced by "coo_default" in the same
  73. section.
  74.  
  75. ''',
  76.     'old_content_file': '''[DEFAULT]
  77. deprecated_coo_default = value_foo
  78. number1 = 10
  79.  
  80. [group1]
  81. bar_group1 = value_bar
  82. number2 = 20
  83.  
  84. ''',
  85.     'expected': '''[DEFAULT]
  86.  
  87. # Lists configuration groups that provide more details for accessing
  88. # configuration settings from locations other than local files. (list
  89. # value)
  90. config_source =
  91.  
  92. # This option is to replace deprecated_coo_default option. (string
  93. # value)
  94. # Deprecated group/name - [DEFAULT]/deprecated_coo_default
  95. coo_default = value_foo
  96.  
  97. # number1 option (integer value)
  98. number1 = 10
  99.  
  100. [group1]
  101.  
  102. # bar option in group1 section (string value)
  103. bar_group1 = value_bar
  104.  
  105. # number2 option (integer value)
  106. number2 = 20
  107. '''
  108. }
  109.  
  110. scenario_3 = {
  111.     'name': 'scenario 3',
  112.     'purpose': '''
  113.  
  114. "deprecated_coo_default" option in DEFAULT section which will be
  115. deprecated in new release and it is replaced by "coo_default" in the same
  116. section.
  117.  
  118. "deprecated_number4" in group1 section will be deprecated in new replease and
  119. "number4" is to replace it.
  120.  
  121. ''',
  122.     'old_content_file': '''[DEFAULT]
  123. deprecated_coo_default = value_foo
  124. number1 = 10
  125.  
  126. [group1]
  127. bar_group1 = value_bar
  128. deprecated_number4 = 20
  129.  
  130. ''',
  131.     'expected': '''[DEFAULT]
  132.  
  133. # Lists configuration groups that provide more details for accessing
  134. # configuration settings from locations other than local files. (list
  135. # value)
  136. config_source =
  137.  
  138. # This option is to replace deprecated_coo_default option. (string
  139. # value)
  140. # Deprecated group/name - [DEFAULT]/deprecated_coo_default
  141. coo_default = value_foo
  142.  
  143. # number1 option (integer value)
  144. number1 = 10
  145.  
  146. # This option will be replaced in the next cycle. (integer value)
  147. # Deprecated group/name - [group1]/deprecated_number4
  148. number4 = 20
  149.  
  150. [group1]
  151.  
  152. # bar option in group1 section (string value)
  153. bar_group1 = value_bar
  154. '''
  155. }
  156.  
  157. scenario_4 = {
  158.     'name': 'scenario 4',
  159.     'purpose': '''
  160.  
  161. "deprecated_choices_opt" in group1 section will be deprecated in new
  162. release by "choices_opt", and its value will be updated as well.
  163. "a" --> 'a_update",
  164. "b" --> "b_update",
  165. "c" --> "c_update".
  166.  
  167. ''',
  168.     'old_content_file': '''[DEFAULT]
  169.  
  170. [group1]
  171. deprecated_choices_opt = a
  172.  
  173. ''',
  174.     'expected': '''[DEFAULT]
  175.  
  176. # Lists configuration groups that provide more details for accessing
  177. # configuration settings from locations other than local files. (list
  178. # value)
  179. config_source =
  180.  
  181. [group2]
  182.  
  183. # This option is to replace deprecated_choices_opt (string value)
  184. # Possible values:
  185. # a_update - <No description provided>
  186. # b - <No description provided>
  187. # c_update - <No description provided>
  188. # Deprecated group/name - [group1]/deprecated_choices_opt
  189. choices_opt = a_update
  190. '''
  191. }
  192.  
  193. scenario_5 = {
  194.     'name': 'scenario 5',
  195.     'purpose': '''
  196.  
  197. In case, users configure options wrong then they need to be checked and write
  198. the configuration file with #.
  199.  
  200. Some wrong options including:
  201. - wrong_option in group2
  202. - wrong_wrong in group4
  203.  
  204. ''',
  205.     'old_content_file': '''[DEFAULT]
  206.  
  207. [group2]
  208.  
  209. multi_opt = 10
  210. multi_opt = 20
  211. wrong_option = foo
  212.  
  213. [group4]
  214. wrong_wrong = bar
  215.  
  216. ''',
  217.     'expected': '''[DEFAULT]
  218.  
  219. # Lists configuration groups that provide more details for accessing
  220. # configuration settings from locations other than local files. (list
  221. # value)
  222. config_source =
  223.  
  224. [group2]
  225.  
  226. # multiple strings (multi valued)
  227. multi_opt = 10
  228. multi_opt = 20
  229. '''
  230. }
  231.  
  232. scenario_6 = {
  233.     'name': 'scenario 6',
  234.     'purpose': '''
  235.  
  236. This scenario includes testing the following cases: deprecated option,
  237. change value option and wrong option.
  238.  
  239. ''',
  240.     'old_content_file': '''[DEFAULT]
  241. deprecated_coo_default = value_foo
  242.  
  243. [group1]
  244. deprecated_number4 = 20
  245. number1 = 1
  246. deprecated_choices_opt = b
  247. wrong = vanduc
  248.  
  249. ''',
  250.     'expected': '''[DEFAULT]
  251.  
  252. # This option is to replace deprecated_choices_opt (string value)
  253. # Possible values:
  254. # a_update - <No description provided>
  255. # b - <No description provided>
  256. # c_update - <No description provided>
  257. # Deprecated group/name - [group1]/deprecated_choices_opt
  258. choices_opt = b
  259.  
  260. # Lists configuration groups that provide more details for accessing
  261. # configuration settings from locations other than local files. (list
  262. # value)
  263. config_source =
  264.  
  265. # This option is to replace deprecated_coo_default option. (string
  266. # value)
  267. # Deprecated group/name - [DEFAULT]/deprecated_coo_default
  268. coo_default = value_foo
  269.  
  270. [group1]
  271.  
  272. # number1 option (integer value)
  273. number1 = 1
  274.  
  275. [group2]
  276.  
  277. # This option will be replaced in the next cycle. (integer value)
  278. # Deprecated group/name - [group1]/deprecated_number4
  279. number4 = 20
  280. '''
  281. }
  282.  
  283. scenario_7 = {
  284.     'name': 'scenario 7',
  285.     'purpose': '''
  286.  
  287. This scenario is to migrate old config to new config that use multiple
  288. namespaces
  289.  
  290. ''',
  291.     'old_content_file': '''[DEFAULT]
  292. deprecated_coo_default = value_foo
  293. port_opt = 80
  294.  
  295. [group1]
  296. deprecated_number4 = 20
  297. number1 = 1
  298. deprecated_choices_opt = b
  299. wrong = xyz
  300.  
  301. ''',
  302.     'expected': '''[DEFAULT]
  303.  
  304. # This option is to replace deprecated_choices_opt (string value)
  305. # Possible values:
  306. # a_update - <No description provided>
  307. # b - <No description provided>
  308. # c_update - <No description provided>
  309. # Deprecated group/name - [group1]/deprecated_choices_opt
  310. choices_opt = b
  311.  
  312. # Lists configuration groups that provide more details for accessing
  313. # configuration settings from locations other than local files. (list
  314. # value)
  315. config_source =
  316.  
  317. # This option is to replace deprecated_coo_default option. (string
  318. # value)
  319. # Deprecated group/name - [DEFAULT]/deprecated_coo_default
  320. coo_default = value_foo
  321.  
  322. # a port (port value)
  323. # Minimum value: 0
  324. # Maximum value: 65535
  325. port_opt = 80
  326.  
  327. [group1]
  328.  
  329. # number1 option (integer value)
  330. number1 = 1
  331.  
  332. [group2]
  333.  
  334. # This option will be replaced in the next cycle. (integer value)
  335. # Deprecated group/name - [group1]/deprecated_number4
  336. number4 = 20
  337. '''
  338. }
  339.  
  340. scenario_8 = {
  341.     'name': 'scenario 8',
  342.     'purpose': '''
  343.  
  344. Remove options that are not in any namespace that user input.
  345.  
  346. ''',
  347.     'old_content_file': '''[DEFAULT]
  348. deprecated_coo_default = value_foo
  349. port_opt = 80
  350.  
  351. ''',
  352.     'expected': '''\
  353. [DEFAULT]
  354.  
  355. # Lists configuration groups that provide more details for accessing
  356. # configuration settings from locations other than local files. (list
  357. # value)
  358. config_source =
  359. '''
  360. }
  361.  
  362. scenario_9 = {
  363.     'name': 'scenario 9',
  364.     'purpose': '''
  365.  
  366. This scenario is to test name option with '-' instead '_'
  367. Ex: cfg.StrOpt('log-file')
  368.  
  369.  
  370. ''',
  371.     'old_content_file': '''[DEFAULT]
  372. deprecated_coo_default = value_foo
  373. log_file = /var/log/
  374.  
  375. [group1]
  376. deprecated_number4 = 20
  377. number1 = 1
  378. wrong = xyz
  379.  
  380. ''',
  381.     'expected': '''[DEFAULT]
  382.  
  383. # Lists configuration groups that provide more details for accessing
  384. # configuration settings from locations other than local files. (list
  385. # value)
  386. config_source =
  387.  
  388. # This option is to replace deprecated_coo_default option. (string
  389. # value)
  390. # Deprecated group/name - [DEFAULT]/deprecated_coo_default
  391. coo_default = value_foo
  392.  
  393. [group1]
  394.  
  395. # log file (string value)
  396. # Deprecated group/name - [DEFAULT]/log_file
  397. log_file = /var/log/
  398.  
  399. # number1 option (integer value)
  400. number1 = 1
  401.  
  402. [group2]
  403.  
  404. # This option will be replaced in the next cycle. (integer value)
  405. # Deprecated group/name - [group1]/deprecated_number4
  406. number4 = 20
  407. '''
  408. }
  409.  
  410. scenario_10 = {
  411.     'name': 'scenario 10',
  412.     'purpose': '''
  413.  
  414. This scenario includes testing the following cases: deprecated option,
  415. change value option and wrong option.
  416.  
  417. ''',
  418.     'old_content_file': '''[DEFAULT]
  419. deprecated_coo_default = value_foo
  420. choices_opt1 = a
  421. notification_driver = noop
  422. notification_driver = log
  423. notification_driver = test
  424. deprecated_list_opt = 1,2,3
  425.  
  426. [group1]
  427. deprecated_number4 = 20
  428. number1 = 1
  429. wrong = vanduc
  430.  
  431. ''',
  432.     'expected': '''[DEFAULT]
  433.  
  434. # a choice opt (string value)
  435. # Possible values:
  436. # a_update - <No description provided>
  437. # b - <No description provided>
  438. # c_update - <No description provided>
  439. choices_opt1 = a_update
  440.  
  441. # Lists configuration groups that provide more details for accessing
  442. # configuration settings from locations other than local files. (list
  443. # value)
  444. config_source =
  445.  
  446. # This option is to replace deprecated_coo_default option. (string
  447. # value)
  448. # Deprecated group/name - [DEFAULT]/deprecated_coo_default
  449. coo_default = value_foo
  450.  
  451. # a list (list value)
  452. # Deprecated group/name - [DEFAULT]/deprecated_list_opt
  453. list_opt = 1,2,3
  454.  
  455. [group1]
  456.  
  457. # The Drivers(s) to handle sending notifications. Possible values are
  458. # messaging, messagingv2, routing, log, test, noop (multi valued)
  459. # Deprecated group/name - [DEFAULT]/notification_driver
  460. driver = noop
  461. driver = log
  462. driver = test
  463.  
  464. # number1 option (integer value)
  465. number1 = 1
  466.  
  467. [group2]
  468.  
  469. # This option will be replaced in the next cycle. (integer value)
  470. # Deprecated group/name - [group1]/deprecated_number4
  471. number4 = 20
  472. '''
  473. }
  474.  
  475.  
  476. class MigratorTestCase(base.BaseTestCase):
  477.     groups = {
  478.         'group1': cfg.OptGroup(name='group1', title='Group 1'),
  479.         'group2': cfg.OptGroup(name='group2', title='Group 2'),
  480.         'group3': cfg.OptGroup(name='group3', title='Group 3',
  481.                                help='Group3 group'),
  482.     }
  483.  
  484.     opts = {
  485.         'foo_default': cfg.StrOpt('foo_default', help='foo option in DEFAULT '
  486.                                                       'section'),
  487.         'bar_group1': cfg.StrOpt('bar_group1', help='bar option in group1 '
  488.                                                     'section'),
  489.         'kaka_group2': cfg.StrOpt('kaka_group2', help='kaka option in group2 '
  490.                                                       'section'),
  491.         'foo-bar': cfg.StrOpt('foo-bar', help='foobar'),
  492.         'number1': cfg.IntOpt('number1', default=10, help='number1 option'),
  493.         'number2': cfg.IntOpt('number2', default=20, help='number2 option'),
  494.         'number3': cfg.IntOpt('number3', help='This option is to replace '
  495.                                               'deprecated_number3'),
  496.         'bool_opt': cfg.BoolOpt('bool_opt',
  497.                                 default=False,
  498.                                 help='a boolean'),
  499.         'list_opt': cfg.ListOpt('list_opt',
  500.                                 deprecated_name='deprecated_list_opt',
  501.                                 default=['1', '2', '3'],
  502.                                 help='a list'),
  503.         'deprecated_list_opt': cfg.ListOpt('deprecated_list_opt',
  504.                                            default=['1', '2', '3'],
  505.                                            help='a list'),
  506.         'dict_opt': cfg.DictOpt('dict_opt',
  507.                                 default={'1': 'yes', '2': 'no'},
  508.                                 help='a dict'),
  509.         'port_opt': cfg.PortOpt('port_opt',
  510.                                 default=80,
  511.                                 help='a port'),
  512.         'hostname_opt': cfg.HostnameOpt('hostname_opt',
  513.                                         default='compute01.nova.site1',
  514.                                         help='a hostname'),
  515.         'uri_opt': cfg.URIOpt('uri_opt',
  516.                               default='http://example.com',
  517.                               help='a URI'),
  518.         'multi_opt': cfg.MultiStrOpt('multi_opt',
  519.                                      default=['1', '2', '3'],
  520.                                      help='multiple strings'),
  521.         'coo_default': cfg.StrOpt('coo_default',
  522.                                   deprecated_name='deprecated_coo_default',
  523.                                   help='This option is to replace '
  524.                                        'deprecated_coo_default option.'),
  525.         'deprecated_coo_default': cfg.StrOpt('deprecated_coo_default',
  526.                                              help='This option will be '
  527.                                                   'replaced in the next '
  528.                                                   'cycle.'),
  529.         'number4': cfg.IntOpt('number4',
  530.                               deprecated_name='deprecated_number4',
  531.                               deprecated_group='group1',
  532.                               help='This option will be replaced '
  533.                                    'in the next cycle.'),
  534.         'deprecated_number4': cfg.IntOpt('deprecated_number4',
  535.                                          help='This option is to replace '
  536.                                               'number4 in group1 section.'),
  537.         'choices_opt': cfg.StrOpt('choices_opt',
  538.                                   deprecated_name='deprecated_choices_opt',
  539.                                   deprecated_group='group1',
  540.                                   choices=('a_update', 'b', 'c_update'),
  541.                                   upgrade_value={'a': 'a_update',
  542.                                                  'c': 'c_update'},
  543.                                   help='This option is to replace '
  544.                                        'deprecated_choices_opt'),
  545.         'deprecated_choices_opt': cfg.StrOpt('deprecated_choices_opt',
  546.                                              choices=('a', 'b', 'c'),
  547.                                              help='This option will be '
  548.                                                   'replaced in the next '
  549.                                                   'cycle.'),
  550.         'choices-opt1': cfg.StrOpt('choices-opt1',
  551.                                    choices=('a_update', 'b', 'c_update'),
  552.                                    upgrade_value={'a': 'a_update',
  553.                                                   'c': 'c_update'},
  554.                                    help='a choice opt'),
  555.         'log-file': cfg.StrOpt('log-file',
  556.                                deprecated_name='log-file',
  557.                                deprecated_group='DEFAULT',
  558.                                help='log file'),
  559.         'driver': cfg.MultiStrOpt('driver',
  560.                                   default=[],
  561.                                   deprecated_name='notification_driver',
  562.                                   deprecated_group='DEFAULT',
  563.                                   help='The Drivers(s) to handle sending notifications. '
  564.                                        'Possible values are messaging, messagingv2, '
  565.                                        'routing, log, test, noop'),
  566.         'notification_driver': cfg.MultiStrOpt('notification_driver',
  567.                                                default=[],
  568.                                                help='The Drivers(s) to handle sending notifications. '
  569.                                                     'Possible values are messaging, messagingv2, '
  570.                                                     'routing, log, test, noop'),
  571.     }
  572.  
  573.     content_scenarios = [
  574.         (scenario_1['name'], {
  575.             'name_scenario': scenario_1['name'],
  576.             'opts': [
  577.                 ('namespace1', [(None, [opts['foo_default'],
  578.                                         opts['number1']]),
  579.                                 (groups['group1'], [opts['bar_group1'],
  580.                                                     opts['number2']])])],
  581.             'expected': scenario_1['expected'],
  582.             'old_content_file': scenario_1['old_content_file']}),
  583.  
  584.         (scenario_2['name'], {
  585.             'name_scenario': scenario_2['name'],
  586.             'opts': [
  587.                 ('namespace1', [(None, [opts['coo_default'],
  588.                                         opts['number1']]),
  589.                                 (groups['group1'], [opts['bar_group1'],
  590.                                                     opts['number2']])])],
  591.             'expected': scenario_2['expected'],
  592.             'old_content_file': scenario_2['old_content_file']}),
  593.  
  594.         (scenario_3['name'], {
  595.             'name_scenario': scenario_3['name'],
  596.             'opts': [
  597.                 ('namespace1', [(None, [opts['coo_default'],
  598.                                         opts['number1'],
  599.                                         opts['number4']]),
  600.                                 (groups['group1'], [opts['bar_group1']])])],
  601.             'expected': scenario_3['expected'],
  602.             'old_content_file': scenario_3['old_content_file']}),
  603.  
  604.         (scenario_4['name'], {
  605.             'name_scenario': scenario_4['name'],
  606.             'opts': [
  607.                 ('namespace1', [(groups['group2'],
  608.                                  [opts['choices_opt']])])],
  609.             'expected': scenario_4['expected'],
  610.             'old_content_file': scenario_4['old_content_file']}),
  611.  
  612.         (scenario_5['name'], {
  613.             'name_scenario': scenario_5['name'],
  614.             'opts': [
  615.                 ('namespace1', [(groups['group2'], [opts['multi_opt']])])],
  616.             'expected': scenario_5['expected'],
  617.             'old_content_file': scenario_5['old_content_file'],
  618.             'log_warning': True}),
  619.  
  620.         (scenario_6['name'], {
  621.             'name_scenario': scenario_6['name'],
  622.             'opts': [
  623.                 ('namespace1', [(None, [opts['coo_default'],
  624.                                         opts['choices_opt']]),
  625.                                 (groups['group1'], [opts['number1']]),
  626.                                 (groups['group2'], [opts['number4']]),
  627.                                 (groups['group3'], [opts['number2']]), ])],
  628.             'expected': scenario_6['expected'],
  629.             'old_content_file': scenario_6['old_content_file'],
  630.             'log_warning': True}),
  631.  
  632.         (scenario_7['name'], {
  633.             'name_scenario': scenario_7['name'],
  634.             'opts': [
  635.                 ('namespace1', [(None, [opts['coo_default'],
  636.                                         opts['choices_opt']]),
  637.                                 (groups['group1'], [opts['number1']]), ]),
  638.                 ('namespace2', [(None, [opts['port_opt']]),
  639.                                 (groups['group2'], [opts['number4']]), ])],
  640.             'expected': scenario_7['expected'],
  641.             'old_content_file': scenario_7['old_content_file'],
  642.             'log_warning': True}),
  643.  
  644.         (scenario_8['name'], {
  645.             'name_scenario': scenario_8['name'],
  646.             'opts': [
  647.                 ('namespace1', [(None, [opts['uri_opt'],
  648.                                         opts['hostname_opt']])]),
  649.                 ('namespace2', [(groups['group2'], [opts['bool_opt']]), ])],
  650.             'expected': scenario_8['expected'],
  651.             'old_content_file': scenario_8['old_content_file'],
  652.             'log_warning': True}),
  653.  
  654.         (scenario_9['name'], {
  655.             'name_scenario': scenario_9['name'],
  656.             'opts': [
  657.                 ('namespace1', [(None, [opts['coo_default']]),
  658.                                 (groups['group1'], [opts['number1']]), ]),
  659.                 ('namespace2', [(groups['group1'], [opts['log-file']]),
  660.                                 (groups['group2'], [opts['number4']]), ])],
  661.             'expected': scenario_9['expected'],
  662.             'old_content_file': scenario_9['old_content_file'],
  663.             'log_warning': True}),
  664.  
  665.         (scenario_10['name'], {
  666.             'name_scenario': scenario_10['name'],
  667.             'opts': [
  668.                 ('namespace1', [(None, [opts['coo_default'],
  669.                                         opts['choices-opt1'],
  670.                                         opts['list_opt']]),
  671.                                 (groups['group1'], [opts['number1'],
  672.                                                     opts['driver']]),
  673.                                 (groups['group2'], [opts['number4']]),
  674.                                 (groups['group3'], [opts['number2']]), ])],
  675.             'expected': scenario_10['expected'],
  676.             'old_content_file': scenario_10['old_content_file'],
  677.             'log_warning': True}),
  678.  
  679.     ]
  680.  
  681.     output_file_scenarios = [
  682.         ('output_file',
  683.          {'output_file': 'new_configuration.conf',
  684.           'old_config_file': 'old_configuration.conf'}),
  685.     ]
  686.  
  687.     def setUp(self):
  688.         super(MigratorTestCase, self).setUp()
  689.  
  690.         self.conf = cfg.ConfigOpts()
  691.         self.config_fixture = config_fixture.Config(self.conf)
  692.         self.config = self.config_fixture.config
  693.         self.useFixture(self.config_fixture)
  694.  
  695.         self.tempdir = self.useFixture(fixtures.TempDir())
  696.  
  697.     @classmethod
  698.     def generate_scenarios(cls):
  699.         cls.scenarios = testscenarios.multiply_scenarios(
  700.             cls.content_scenarios,
  701.             cls.output_file_scenarios)
  702.  
  703.     @mock.patch.object(generator, '_get_raw_opts_loaders')
  704.     @mock.patch.object(migrator, 'LOG')
  705.     def test_migrator(self, mock_log, raw_opts_loader):
  706.  
  707.         migrator.register_cli_opts(self.conf)
  708.  
  709.         # Writing old configuration file
  710.         old_config_file = self.tempdir.join(self.old_config_file)
  711.         with open(old_config_file, 'w') as f:
  712.             f.write(self.old_content_file)
  713.         self.config(input_file=old_config_file)
  714.  
  715.         namespaces = [i[0] for i in self.opts]
  716.         self.config(namespace=namespaces)
  717.  
  718.         for group in self.groups.values():
  719.             self.conf.register_group(group)
  720.  
  721.         wrap_width = getattr(self, 'wrap_width', None)
  722.         if wrap_width is not None:
  723.             self.config(wrap_width=wrap_width)
  724.  
  725.         output_file = self.tempdir.join(self.output_file)
  726.         self.config(output_file=output_file)
  727.  
  728.         raw_opts_loader.return_value = [
  729.             (ns, lambda opts=opts: opts)
  730.             for ns, opts in self.opts
  731.         ]
  732.  
  733.         migrator.migrator(self.conf)
  734.  
  735.         log_warning = getattr(self, 'log_warning', False)
  736.         if log_warning:
  737.             mock_log.warning.assert_called()
  738.         else:
  739.             mock_log.warning.assert_not_called()
  740.  
  741.         with open(output_file, 'r') as f:
  742.             actual = f.read()
  743.             self.assertEqual(self.expected, actual)
  744.  
  745.  
  746. MigratorTestCase.generate_scenarios()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement