Skip to content
This repository has been archived by the owner on Mar 25, 2023. It is now read-only.

feat(sg): set name for private security groups from vm name (closes #862) #905

Merged
merged 1 commit into from
Jan 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('Test service offering reducer', () => {
payload: [{ id: '1', name: 'off1' }, { id: '2', name: 'off2' }]
});
expect(state)
.toEqual({
.toEqual(<any>{
ids: ['1', '2'],
entities: { 1: { id: '1', name: 'off1' }, 2: { id: '2', name: 'off2' } },
loading: false,
Expand All @@ -76,7 +76,7 @@ describe('Test service offering reducer', () => {
payload: { 'filterOfferings': false }
});
expect(state)
.toEqual({
.toEqual(<any>{
ids: [],
entities: {},
loading: false,
Expand All @@ -94,7 +94,7 @@ describe('Test service offering reducer', () => {
});

expect(state)
.toEqual({
.toEqual(<any>{
ids: [],
entities: {},
loading: false,
Expand All @@ -112,7 +112,7 @@ describe('Test service offering reducer', () => {
});

expect(state)
.toEqual({
.toEqual(<any>{
ids: [],
entities: {},
loading: false,
Expand All @@ -133,7 +133,7 @@ describe('Test service offering reducer', () => {
});

expect(state)
.toEqual({
.toEqual(<any>{
ids: [],
entities: {},
loading: false,
Expand All @@ -153,7 +153,7 @@ describe('Test service offering reducer', () => {
payload: [{ id: '1', name: 'off1' }, { id: '2', name: 'off2' }]
});
expect(state)
.toEqual({
.toEqual(<any>{
ids: ['1', '2'],
entities: { 1: { id: '1', name: 'off1' }, 2: { id: '2', name: 'off2' } },
loading: false,
Expand Down Expand Up @@ -323,7 +323,7 @@ describe('Test service offering reducer', () => {
},
resourceUsage
);
expect(result3).toEqual({
expect(result3).toEqual(<any>{
cpunumber: { max: 2, min: 1 },
memory: { max: 2, min: 1 },
cpuspeed: { min: 1, max: 2 }
Expand Down
2 changes: 1 addition & 1 deletion src/app/reducers/vm/redux/vm-creation.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ export class VirtualMachineCreationEffects {
if (this.createSecurityGroup(state)) {
this.handleDeploymentMessages({ stage: VmDeploymentStage.SG_GROUP_CREATION });

return this.vmCreationSecurityGroupService.getSecurityGroupCreationRequest(state.securityGroupData);
return this.vmCreationSecurityGroupService.getSecurityGroupCreationRequest(state);
} else {
return Observable.of(null);
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/shared/services/service-offering.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ describe('Service-offering service', () => {
deploymentplanner: '',
domain: 'domainId'
};
const availableOfferings = [
const availableOfferings = <any>[
{
id: '1',
name: 'Service Offering',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { Injectable } from '@angular/core';
import { TestBed } from '@angular/core/testing';
// tslint:disable-next-line
import { PrivateSecurityGroupCreationService } from '../../../security-group/services/creation-services/private-security-group-creation.service';
// tslint:disable-next-line
import { SharedSecurityGroupCreationService } from '../../../security-group/services/creation-services/shared-security-group-creation.service';
// tslint:disable-next-line
import { TemplateSecurityGroupCreationService } from '../../../security-group/services/creation-services/template-security-group-creation.service';
import { NetworkRuleService } from '../../../security-group/services/network-rule.service';
import { SecurityGroupService } from '../../../security-group/services/security-group.service';
import { AsyncJobService } from '../../../shared/services/async-job.service';
import { ConfigService } from '../../../shared/services/config.service';
import { MarkForRemovalService } from '../../../shared/services/tags/mark-for-removal.service';
import { SecurityGroupTagService } from '../../../shared/services/tags/security-group-tag.service';
import { TagService } from '../../../shared/services/tags/tag.service';
import { VmCreationSecurityGroupService } from './vm-creation-security-group.service';

describe('VM creation security group service', () => {
let vmCreationSecurityGroupService: VmCreationSecurityGroupService;

beforeEach(() => {
TestBed.configureTestingModule({
providers: [
ConfigService,
SecurityGroupService,
VmCreationSecurityGroupService,
TemplateSecurityGroupCreationService,
PrivateSecurityGroupCreationService,
SharedSecurityGroupCreationService,
SecurityGroupTagService,
MarkForRemovalService,
TagService,
AsyncJobService,
NetworkRuleService
],
imports: [
HttpClientTestingModule
]
});
vmCreationSecurityGroupService = TestBed.get(VmCreationSecurityGroupService);
});

it('should assign VM name to the private security group', () => {
const result = vmCreationSecurityGroupService['securityGroupCreationData']('new-vm');
expect(result.name).toBe('sg-new-vm');
});
});
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { Injectable } from '@angular/core';
import { VmCreationState } from '../data/vm-creation-state';
import { VmCreationSecurityGroupData } from '../security-group/vm-creation-security-group-data';
import { Observable } from 'rxjs/Observable';
import { VmCreationSecurityGroupMode } from '../security-group/vm-creation-security-group-mode';
import { GROUP_POSTFIX, SecurityGroupService } from '../../../security-group/services/security-group.service';
import {
GROUP_POSTFIX,
SecurityGroupService
} from '../../../security-group/services/security-group.service';
import { NetworkRule } from '../../../security-group/network-rule.model';
import { Rules } from '../../../shared/components/security-group-builder/rules';
import { Utils } from '../../../shared/services/utils/utils.service';
Expand All @@ -14,21 +18,17 @@ export class VmCreationSecurityGroupService {
constructor(private securityGroupService: SecurityGroupService) {
}

public getSecurityGroupCreationRequest(securityGroupData: VmCreationSecurityGroupData): Observable<SecurityGroup[]> {
if (securityGroupData.mode === VmCreationSecurityGroupMode.Builder) {
const data = this.securityGroupCreationData;
const rules = this.getSecurityGroupCreationRules(securityGroupData.rules);
return this.securityGroupService.createPrivate(data, rules).map(securityGroup => [securityGroup]);
public getSecurityGroupCreationRequest(state: VmCreationState): Observable<SecurityGroup[]> {
if (state.securityGroupData.mode === VmCreationSecurityGroupMode.Builder) {
const data = this.securityGroupCreationData(state.displayName);
const rules = this.getSecurityGroupCreationRules(state.securityGroupData.rules);
return this.securityGroupService.createPrivate(data, rules)
.map(securityGroup => [securityGroup]);
} else {
return Observable.of(securityGroupData.securityGroups);
return Observable.of(state.securityGroupData.securityGroups);
}
}

private get securityGroupCreationData(): any {
return {
name: this.name
};
}

private get name(): string {
return Utils.getUniqueId() + GROUP_POSTFIX;
Expand All @@ -40,4 +40,10 @@ export class VmCreationSecurityGroupService {
egress: rules.egress
};
}

private securityGroupCreationData(vmDisplayName?: string): any {
return {
name: vmDisplayName ? `sg-${ vmDisplayName }` : this.name
};
}
}