Skip to content

Commit

Permalink
CODENVY-1224 Make snapshot images use tag field
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihail Kuznyetsov committed Dec 26, 2016
1 parent 73685c1 commit 3bb3d2e
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 2 deletions.
Expand Up @@ -881,13 +881,17 @@ private Instance startInstance(boolean recover,

MachineImpl originMachine = new MachineImpl(machine);
try {
MachineSource machineSource = null;
MachineSourceImpl machineSource = null;
if (recover) {
SnapshotImpl snapshot = snapshotDao.getSnapshot(machine.getWorkspaceId(),
machine.getEnvName(),
machine.getConfig().getName());

machineSource = snapshot.getMachineSource();
// Snapshot image location has SHA-256 digest which needs to be removed,
// otherwise it will be pulled without tag and cause problems
String imageName = machineSource.getLocation();
if (imageName.contains("@sha256:"))
machineSource.setLocation(imageName.substring(0, imageName.indexOf('@')));
}

instance = machineStarter.startMachine(machineLogger, machineSource);
Expand Down
Expand Up @@ -432,6 +432,67 @@ public void shouldSetDefaultRamToMachineWithoutRamOnMachineStart() throws Except
assertEquals((long)actualService.getMemLimit(), DEFAULT_MACHINE_MEM_LIMIT_MB * 1024L * 1024L);
}

@Test
public void shouldBeAbleToStartEnvironmentWithRrcover() throws Exception {
// given
SnapshotImpl snapshot = mock(SnapshotImpl.class);
MachineSourceImpl machineSource = new MachineSourceImpl("image", "registry.com/snapshot123:latest@sha256:abc1234567890", null);
when(snapshotDao.getSnapshot(anyString(), anyString(), anyString())).thenReturn(snapshot);
when(snapshot.getMachineSource()).thenReturn(machineSource);

// given
EnvironmentImpl env = createEnv();
String envName = "env-1";
String workspaceId = "wsId";
List<Instance> expectedMachines = new ArrayList<>();
when(machineProvider.startService(anyString(),
eq(workspaceId),
eq(envName),
anyString(),
anyBoolean(),
anyString(),
any(CheServiceImpl.class),
any(LineConsumer.class)))
.thenAnswer(invocationOnMock -> {
Object[] arguments = invocationOnMock.getArguments();
String machineName = (String)arguments[3];
boolean isDev = (boolean)arguments[4];
CheServiceImpl service = (CheServiceImpl)arguments[6];
Machine machine = createMachine(workspaceId,
envName,
service,
machineName,
isDev);
NoOpMachineInstance instance = spy(new NoOpMachineInstance(machine));
expectedMachines.add(instance);
return instance;
});
when(environmentParser.parse(env)).thenReturn(createCheServicesEnv());

// when
List<Instance> machines = engine.start(workspaceId,
envName,
env,
true,
messageConsumer);

// then
assertEquals(machines, expectedMachines);

ArgumentCaptor<CheServiceImpl> captor = ArgumentCaptor.forClass(CheServiceImpl.class);
verify(machineProvider).startService(anyString(),
anyString(),
anyString(),
anyString(),
eq(false),
anyString(),
captor.capture(),
any(LineConsumer.class));
CheServiceImpl actualService = captor.getValue();

assertEquals(actualService.getImage(), "registry.com/snapshot123:latest");
}

@Test
public void shouldUseConfiguredInMachineRamInsteadOfSetDefaultOnMachineStart() throws Exception {
// given
Expand Down

0 comments on commit 3bb3d2e

Please sign in to comment.