Revision 70b634e6

b/lib/cmdlib/backup.py
396 396
    activate_disks = not self.instance.disks_active
397 397

  
398 398
    if activate_disks:
399
      # Activate the instance disks if we'exporting a stopped instance
399
      # Activate the instance disks if we're exporting a stopped instance
400 400
      feedback_fn("Activating disks for %s" % self.instance.name)
401 401
      StartInstanceDisks(self, self.instance, None)
402 402

  
b/test/py/cmdlib/backup_unittest.py
21 21

  
22 22
"""Tests for LUBackup*"""
23 23

  
24
import mock
25

  
26 24
from ganeti import constants
25
from ganeti import objects
27 26
from ganeti import opcodes
28 27
from ganeti import query
29 28

  
......
95 94
    self.ExecOpCode(op)
96 95

  
97 96

  
97
class TestLUBackupExportBase(CmdlibTestCase):
98
  def setUp(self):
99
    super(TestLUBackupExportBase, self).setUp()
100

  
101
    self.rpc.call_instance_start.return_value = \
102
      self.RpcResultsBuilder() \
103
        .CreateSuccessfulNodeResult(self.master, True)
104

  
105
    self.rpc.call_blockdev_assemble.return_value = \
106
      self.RpcResultsBuilder() \
107
        .CreateSuccessfulNodeResult(self.master, None)
108

  
109
    self.rpc.call_blockdev_shutdown.return_value = \
110
      self.RpcResultsBuilder() \
111
        .CreateSuccessfulNodeResult(self.master, None)
112

  
113
    self.rpc.call_blockdev_snapshot.return_value = \
114
      self.RpcResultsBuilder() \
115
        .CreateSuccessfulNodeResult(self.master, ("mock_vg", "mock_id"))
116

  
117
    self.rpc.call_blockdev_remove.return_value = \
118
      self.RpcResultsBuilder() \
119
        .CreateSuccessfulNodeResult(self.master, None)
120

  
121
    self.rpc.call_export_start.return_value = \
122
      self.RpcResultsBuilder() \
123
        .CreateSuccessfulNodeResult(self.master, "export_daemon")
124

  
125
    def ImpExpStatus(node_uuid, name):
126
      return self.RpcResultsBuilder() \
127
               .CreateSuccessfulNodeResult(node_uuid,
128
                                           [objects.ImportExportStatus(
129
                                             exit_status=0
130
                                           )])
131
    self.rpc.call_impexp_status.side_effect = ImpExpStatus
132

  
133
    def ImpExpCleanup(node_uuid, name):
134
      return self.RpcResultsBuilder() \
135
               .CreateSuccessfulNodeResult(node_uuid)
136
    self.rpc.call_impexp_cleanup.side_effect = ImpExpCleanup
137

  
138
    self.rpc.call_finalize_export.return_value = \
139
      self.RpcResultsBuilder() \
140
        .CreateSuccessfulNodeResult(self.master, None)
141

  
142
  def testRemoveRunningInstanceWithoutShutdown(self):
143
    inst = self.cfg.AddNewInstance(admin_state=constants.ADMINST_UP)
144
    op = opcodes.OpBackupExport(instance_name=inst.name,
145
                                target_node=self.master.name,
146
                                shutdown=False,
147
                                remove_instance=True)
148
    self.ExecOpCodeExpectOpPrereqError(
149
      op, "Can not remove instance without shutting it down before")
150

  
151
  def testUnsupportedDiskTemplate(self):
152
    inst = self.cfg.AddNewInstance(disk_template=constants.DT_FILE)
153
    op = opcodes.OpBackupExport(instance_name=inst.name,
154
                                target_node=self.master.name)
155
    self.ExecOpCodeExpectOpPrereqError(
156
      op, "Export not supported for instances with file-based disks")
157

  
158

  
159
class TestLUBackupExportLocalExport(TestLUBackupExportBase):
160
  def setUp(self):
161
    super(TestLUBackupExportLocalExport, self).setUp()
162

  
163
    self.inst = self.cfg.AddNewInstance()
164
    self.target_node = self.cfg.AddNewNode()
165
    self.op = opcodes.OpBackupExport(mode=constants.EXPORT_MODE_LOCAL,
166
                                     instance_name=self.inst.name,
167
                                     target_node=self.target_node.name)
168

  
169
    self.rpc.call_import_start.return_value = \
170
      self.RpcResultsBuilder() \
171
        .CreateSuccessfulNodeResult(self.target_node, "import_daemon")
172

  
173
  def testExportWithShutdown(self):
174
    inst = self.cfg.AddNewInstance(admin_state=constants.ADMINST_UP)
175
    op = self.CopyOpCode(self.op, instance_name=inst.name, shutdown=True)
176
    self.ExecOpCode(op)
177

  
178
  def testExportDeactivatedDisks(self):
179
    self.ExecOpCode(self.op)
180

  
181
  def testExportRemoveInstance(self):
182
    op = self.CopyOpCode(self.op, remove_instance=True)
183
    self.ExecOpCode(op)
184

  
185

  
186
class TestLUBackupExportRemoteExport(TestLUBackupExportBase):
187
  def setUp(self):
188
    super(TestLUBackupExportRemoteExport, self).setUp()
189

  
190
    self.inst = self.cfg.AddNewInstance()
191
    self.op = opcodes.OpBackupExport(mode=constants.EXPORT_MODE_REMOTE,
192
                                     instance_name=self.inst.name,
193
                                     target_node=[],
194
                                     x509_key_name=["mock_key_name"],
195
                                     destination_x509_ca="mock_dest_ca")
196

  
197
  def testRemoteExportWithoutX509KeyName(self):
198
    op = self.CopyOpCode(self.op, x509_key_name=self.REMOVE)
199
    self.ExecOpCodeExpectOpPrereqError(op,
200
                                       "Missing X509 key name for encryption")
201

  
202
  def testRemoteExportWithoutX509DestCa(self):
203
    op = self.CopyOpCode(self.op, destination_x509_ca=self.REMOVE)
204
    self.ExecOpCodeExpectOpPrereqError(op,
205
                                       "Missing destination X509 CA")
206

  
207

  
98 208
if __name__ == "__main__":
99 209
  testutils.GanetiTestProgram()

Also available in: Unified diff