def set_up_arg_parser(): # zpm already has some a nice arg parser and command config code, # so let's extend/reuse/abuse that. # # TODO(larsbutler): Extract this generic command arg code to a shared # common library? parser = commands.set_up_arg_parser() parser.description = 'ZeroVM command line utility' parser.epilog = ("See 'zvm <command> --help' for more information on a " "specific command.") return parser
def test_deploy_project_execute(self): parser = commands.set_up_arg_parser() args = parser.parse_args(['deploy', 'foo', self.zapp_path, '--exec']) job_path = 'boot/system.map' job_json = self.job_json_contents.decode('utf-8') job = json.loads(job_json) with mock.patch('zpmlib.zpm._get_zerocloud_conn') as gzc: gzc.return_value = self.conn get_object = self.conn.get_object get_object.return_value = ([], job_json) post_job = self.conn.post_job zpm.deploy_project(args) assert get_object.call_args_list == [mock.call('foo', job_path)] assert post_job.call_args_list == [mock.call(job)]
def test_deploy_project_execute(self): job_path = 'boot/system.map' job_json = self.job_json_contents.decode('utf-8') job_dict = json.loads(job_json) class FakeZeroCloudConnection(mock.Mock): url = 'http://127.0.0.1' token = 'abc123' def post_job(self, job, response_dict=None, response_body_buffer=None): response_dict['status'] = 200 response_dict['reason'] = 'OK' response_dict['headers'] = { 'x-nexe-system': 'node-1', 'x-nexe-cdr-line': ('5.121, 4.993, 0.13 3.84 1025 75943662 23 735 8 399 0 ' '0'), 'x-nexe-status': 'ok', 'x-nexe-retcode': '0', } # Check the job is passed properly here assert job == job_dict def get_container(self, *args, **kwargs): return {}, [] self.conn = FakeZeroCloudConnection() self.conn.auth_version = '1.0' parser = commands.set_up_arg_parser() args = parser.parse_args(['deploy', 'foo', self.zapp_path, '--exec']) with mock.patch('zpmlib.zpm._get_zerocloud_conn') as gzc: gzc.return_value = self.conn self.conn.get_object = mock.Mock() get_object = self.conn.get_object get_object.return_value = ([], job_json) zpm.deploy_project(args) assert get_object.call_args_list == [mock.call('foo', job_path)]
def test_deploy_project_execute(self): job_path = 'boot/system.map' job_json = self.job_json_contents.decode('utf-8') job_dict = json.loads(job_json) class FakeZeroCloudConnection(mock.Mock): url = 'http://127.0.0.1' token = 'abc123' def post_job(self, job, response_dict=None, response_body_buffer=None): response_dict['status'] = 200 response_dict['reason'] = 'OK' response_dict['headers'] = { 'x-nexe-system': 'node-1', 'x-nexe-cdr-line': ( '5.121, 4.993, 0.13 3.84 1025 75943662 23 735 8 399 0 ' '0' ), 'x-nexe-status': 'ok', 'x-nexe-retcode': '0', } # Check the job is passed properly here assert job == job_dict def get_container(self, *args, **kwargs): return {}, [] self.conn = FakeZeroCloudConnection() self.conn.auth_version = '1.0' parser = commands.set_up_arg_parser() args = parser.parse_args(['deploy', 'foo', self.zapp_path, '--exec']) with mock.patch('zpmlib.zpm._get_zerocloud_conn') as gzc: gzc.return_value = self.conn self.conn.get_object = mock.Mock() get_object = self.conn.get_object get_object.return_value = ([], job_json) zpm.deploy_project(args) assert get_object.call_args_list == [mock.call('foo', job_path)]