On Tue, Aug 20, 2013 at 1:28 PM, Guido Trotter <[email protected]> wrote:
> On Tue, Aug 20, 2013 at 1:08 PM, Thomas Thrainer <[email protected]> > wrote: > > This patch adds basic unit tests for instance import in > > LUInstanceCreate. It does not provide full coverage though. > > > > Signed-off-by: Thomas Thrainer <[email protected]> > > --- > > test/py/cmdlib/instance_unittest.py | 121 > ++++++++++++++++++++++++++++++++++++ > > 1 file changed, 121 insertions(+) > > > > diff --git a/test/py/cmdlib/instance_unittest.py > b/test/py/cmdlib/instance_unittest.py > > index 4b7e54a..0556978 100644 > > --- a/test/py/cmdlib/instance_unittest.py > > +++ b/test/py/cmdlib/instance_unittest.py > > @@ -626,6 +626,127 @@ class TestLUInstanceCreate(CmdlibTestCase): > > wait_for_sync=False) > > self.ExecOpCode(op) > > > > + def testImportPlainFromGivenSrcNode(self): > > + exp_info = """ > > +[export] > > +version=0 > > +os=mock_os > > +[instance] > > +name=old_name.example.com > > +""" > > + > > + self.rpc.call_export_info.return_value = \ > > + self.RpcResultsBuilder() \ > > + .CreateSuccessfulNodeResult(self.master, exp_info) > > + op = self.CopyOpCode(self.plain_op, > > + mode=constants.INSTANCE_IMPORT, > > + src_node=self.master.name) > > + self.ExecOpCode(op) > > + > > + def testImportPlainWithoutSrcNodeNotFound(self): > > + op = self.CopyOpCode(self.plain_op, > > + mode=constants.INSTANCE_IMPORT) > > + self.ExecOpCodeExpectOpPrereqError( > > + op, "No export found for relative path") > > + > > + def testImportPlainWithoutSrcNode(self): > > + exp_info = """ > > +[export] > > +version=0 > > +os=mock_os > > +[instance] > > +name=old_name.example.com > > +""" > > Would it be better to keep the export info files under data/ and open > them with utils.ReadFile()? > I kept the info in the test instead of in separate files for multiple reasons: 1) it's easier to understand the test if all the relevant information is close together rather than distributed over multiple files, 2) the export info is reasonable short and 3) I try to have unit tests as pure as possible (so no I/O, networking, etc.). > > Thanks, > > Guido > -- Thomas Thrainer | Software Engineer | [email protected] | Google Germany GmbH Dienerstr. 12 80331 München Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Geschäftsführer: Graham Law, Christine Elizabeth Flores
