-
Notifications
You must be signed in to change notification settings - Fork 1.3k
engine-storage: fix errored template becomes active #7485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -286,6 +286,23 @@ public void handleSysTemplateDownload(HypervisorType hostHyper, Long dcId) { | |
| } | ||
| } | ||
|
|
||
| protected boolean isSkipTemplateStoreDownload(VMTemplateVO template, Long zoneId) { | ||
| if (template.isPublicTemplate()) { | ||
| return false; | ||
| } | ||
| if (template.isFeatured()) { | ||
| return false; | ||
| } | ||
| if (TemplateType.SYSTEM.equals(template.getTemplateType())) { | ||
| return false; | ||
| } | ||
| if (zoneId != null && _vmTemplateStoreDao.findByTemplateZone(template.getId(), zoneId, DataStoreRole.Image) == null) { | ||
| s_logger.debug(String.format("Template %s is not present on any image store for the zone ID: %d, its download cannot be skipped", template.getUniqueName(), zoneId)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what if it is a direct download template?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Direct-download templates are skipped (already) at line 496 |
||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public void handleTemplateSync(DataStore store) { | ||
| if (store == null) { | ||
|
|
@@ -513,7 +530,7 @@ public void handleTemplateSync(DataStore store) { | |
| continue; | ||
| } | ||
| // if this is private template, skip sync to a new image store | ||
| if (!tmplt.isPublicTemplate() && !tmplt.isFeatured() && tmplt.getTemplateType() != TemplateType.SYSTEM) { | ||
| if (isSkipTemplateStoreDownload(tmplt, zoneId)) { | ||
| s_logger.info("Skip sync downloading private template " + tmplt.getUniqueName() + " to a new image store"); | ||
| continue; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.cloudstack.storage.image; | ||
|
|
||
| import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao; | ||
| import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO; | ||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
| import org.mockito.InjectMocks; | ||
| import org.mockito.Mock; | ||
| import org.mockito.Mockito; | ||
| import org.mockito.Spy; | ||
| import org.mockito.junit.MockitoJUnitRunner; | ||
|
|
||
| import com.cloud.storage.DataStoreRole; | ||
| import com.cloud.storage.Storage; | ||
| import com.cloud.storage.VMTemplateVO; | ||
|
|
||
| @RunWith(MockitoJUnitRunner.class) | ||
| public class TemplateServiceImplTest { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Excellent to see tests @shwstppr ! |
||
|
|
||
| @InjectMocks | ||
| @Spy | ||
| TemplateServiceImpl templateService; | ||
|
|
||
| @Mock | ||
| TemplateDataStoreDao templateDataStoreDao; | ||
|
|
||
| @Test | ||
| public void testIsSkipTemplateStoreDownloadPublicTemplate() { | ||
| VMTemplateVO templateVO = Mockito.mock(VMTemplateVO.class); | ||
| Mockito.when(templateVO.isPublicTemplate()).thenReturn(true); | ||
| Assert.assertFalse(templateService.isSkipTemplateStoreDownload(templateVO, 1L)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testIsSkipTemplateStoreDownloadFeaturedTemplate() { | ||
| VMTemplateVO templateVO = Mockito.mock(VMTemplateVO.class); | ||
| Mockito.when(templateVO.isFeatured()).thenReturn(true); | ||
| Assert.assertFalse(templateService.isSkipTemplateStoreDownload(templateVO, 1L)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testIsSkipTemplateStoreDownloadSystemTemplate() { | ||
| VMTemplateVO templateVO = Mockito.mock(VMTemplateVO.class); | ||
| Mockito.when(templateVO.getTemplateType()).thenReturn(Storage.TemplateType.SYSTEM); | ||
| Assert.assertFalse(templateService.isSkipTemplateStoreDownload(templateVO, 1L)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testIsSkipTemplateStoreDownloadPrivateNoRefTemplate() { | ||
| VMTemplateVO templateVO = Mockito.mock(VMTemplateVO.class); | ||
| long id = 1L; | ||
| Mockito.when(templateVO.getId()).thenReturn(id); | ||
| Mockito.when(templateDataStoreDao.findByTemplateZone(id, id, DataStoreRole.Image)).thenReturn(null); | ||
| Assert.assertFalse(templateService.isSkipTemplateStoreDownload(templateVO, id)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testIsSkipTemplateStoreDownloadPrivateExistingTemplate() { | ||
| VMTemplateVO templateVO = Mockito.mock(VMTemplateVO.class); | ||
| long id = 1L; | ||
| Mockito.when(templateVO.getId()).thenReturn(id); | ||
| Mockito.when(templateDataStoreDao.findByTemplateZone(id, id, DataStoreRole.Image)).thenReturn(Mockito.mock(TemplateDataStoreVO.class)); | ||
| Assert.assertTrue(templateService.isSkipTemplateStoreDownload(templateVO, id)); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shwstppr
if an error template is public or featured, will it become Active ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@weizhouapache no.
Server won't skip download if any of the following condition is true:
Depending upon download status template status will be set later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems I misunderstood the code :-D
is there a scenario that template download is skipped but it is expected behaviour ? direct download ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Direct-download templates are skipped (already) at line 496