def test_node_create_snapshot_external_domain_not_active( self, mock_conn, mock_os, mock_set_snapshot_current, mock_get_snapshots, mock_snapshot_exists, mock_snapshot_xml): mock_snapshot_exists.return_value = False mock_get_snapshots.return_value = [mock.Mock(get_type='external')] node = mock.Mock(uuid='test_node') mock_os.path.exists.return_value = False domain = mock.Mock() domain.isActive.return_value = False domain.snapshotCreateXML.return_value = True mock_conn.return_value.lookupByUUIDString.return_value = domain snapshot_name = factories.fuzzy_string() description = factories.fuzzy_string('description_') xml_fuzzy = factories.fuzzy_string() xml = '<{0}/>'.format(xml_fuzzy) mock_snapshot_xml.return_value = xml disk_only = False external = True dd = DevopsDriver() dd.node_create_snapshot(node, name=snapshot_name, disk_only=disk_only, description=description, external=external) mock_snapshot_xml.assert_called_with(snapshot_name, description, node, disk_only, external, '/path/snap') self.assertEqual(mock_os.makedirs.called, True) self.assertEqual(domain.snapshotCreateXML.called, True) domain.snapshotCreateXML.assert_called_with( xml, libvirt.VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY | libvirt.VIR_DOMAIN_SNAPSHOT_CREATE_REUSE_EXT) mock_set_snapshot_current.assert_called_with(node, snapshot_name)
def test_node_create_snapshot_if_exists(self, mock_conn, mock_snapshot_exists): mock_snapshot_exists.return_value = True mock_conn.return_value.lookupByUUIDString.return_value = mock.Mock() dd = DevopsDriver() dd.node_create_snapshot('node') self.assertEqual(mock_conn.lookupByUUIDString.called, False)
def test_node_create_snapshot_external_if_internal_exists( self, mock_conn, mock_get_snapshots, mock_snapshot_exists, mock_snapshot_xml): mock_snapshot_exists.return_value = False mock_get_snapshots.return_value = [mock.Mock(get_type='internal')] mock_conn.return_value.lookupByUUIDString.return_value = mock.Mock() node = mock.Mock(uuid='test_node') dd = DevopsDriver() dd.node_create_snapshot(node, external=True) self.assertEqual(mock_snapshot_xml.called, False)