func TestNewFactoryGetState(t *testing.T) {
	deps, factory := buildFactory()
	ntpService := boshntp.NewConcreteService(deps.platform.GetFs(), deps.platform.GetDirProvider())
	action, err := factory.Create("get_state")
	assert.NoError(t, err)
	assert.NotNil(t, action)
	assert.Equal(t, newGetState(deps.settings, deps.specService, deps.jobSupervisor, deps.platform.GetVitalsService(), ntpService), action)
}
func NewFactory(
	settingsService boshsettings.Service,
	platform boshplatform.Platform,
	blobstore boshblob.Blobstore,
	taskService boshtask.Service,
	notifier boshnotif.Notifier,
	applier boshappl.Applier,
	compiler boshcomp.Compiler,
	jobSupervisor boshjobsuper.JobSupervisor,
	specService boshas.V1Service,
	drainScriptProvider boshdrain.DrainScriptProvider,
	logger boshlog.Logger,
) (factory Factory) {
	compressor := platform.GetCompressor()
	copier := platform.GetCopier()
	dirProvider := platform.GetDirProvider()
	vitalsService := platform.GetVitalsService()
	ntpService := boshntp.NewConcreteService(platform.GetFs(), dirProvider)

	factory = concreteFactory{
		availableActions: map[string]Action{
			// Task management
			"ping":        NewPing(),
			"get_task":    NewGetTask(taskService),
			"cancel_task": NewCancelTask(taskService),

			// VM admin
			"ssh":        NewSSH(settingsService, platform, dirProvider),
			"fetch_logs": NewFetchLogs(compressor, copier, blobstore, dirProvider),

			// Job management
			"prepare":    NewPrepare(applier),
			"apply":      NewApply(applier, specService, settingsService),
			"start":      NewStart(jobSupervisor),
			"stop":       NewStop(jobSupervisor),
			"drain":      NewDrain(notifier, specService, drainScriptProvider, jobSupervisor),
			"get_state":  NewGetState(settingsService, specService, jobSupervisor, vitalsService, ntpService),
			"run_errand": NewRunErrand(specService, dirProvider.JobsDir(), platform.GetRunner(), logger),

			// Compilation
			"compile_package":    NewCompilePackage(compiler),
			"release_apply_spec": NewReleaseApplySpec(platform),

			// Disk management
			"list_disk":    NewListDisk(settingsService, platform, logger),
			"migrate_disk": NewMigrateDisk(platform, dirProvider),
			"mount_disk":   NewMountDisk(settingsService, platform, platform, dirProvider),
			"unmount_disk": NewUnmountDisk(settingsService, platform),

			// Networking
			"prepare_network_change":     NewPrepareNetworkChange(platform.GetFs(), settingsService),
			"prepare_configure_networks": NewPrepareConfigureNetworks(platform, settingsService),
			"configure_networks":         NewConfigureNetworks(),
		},
	}
	return
}
示例#3
0
func NewFactory(
	settings boshsettings.Service,
	platform boshplatform.Platform,
	blobstore boshblob.Blobstore,
	taskService boshtask.Service,
	notifier boshnotif.Notifier,
	applier boshappl.Applier,
	compiler boshcomp.Compiler,
	jobSupervisor boshjobsuper.JobSupervisor,
	specService boshas.V1Service,
	drainScriptProvider boshdrain.DrainScriptProvider,
) (factory Factory) {
	compressor := platform.GetCompressor()
	copier := platform.GetCopier()
	dirProvider := platform.GetDirProvider()
	vitalsService := platform.GetVitalsService()
	ntpService := boshntp.NewConcreteService(platform.GetFs(), dirProvider)

	factory = concreteFactory{
		availableActions: map[string]Action{
			"apply":        NewApply(applier, specService),
			"drain":        NewDrain(notifier, specService, drainScriptProvider),
			"fetch_logs":   NewLogs(compressor, copier, blobstore, dirProvider),
			"get_task":     NewGetTask(taskService),
			"get_state":    NewGetState(settings, specService, jobSupervisor, vitalsService, ntpService),
			"list_disk":    NewListDisk(settings, platform),
			"migrate_disk": NewMigrateDisk(platform, dirProvider),
			"mount_disk":   NewMountDisk(settings, platform, dirProvider),
			"ping":         NewPing(),
			"prepare_network_change": NewPrepareNetworkChange(platform),
			"ssh":                NewSsh(settings, platform, dirProvider),
			"start":              NewStart(jobSupervisor),
			"stop":               NewStop(jobSupervisor),
			"unmount_disk":       NewUnmountDisk(settings, platform),
			"compile_package":    NewCompilePackage(compiler),
			"release_apply_spec": NewReleaseApplySpec(platform),
		},
	}
	return
}
func init() {
	Describe("concreteFactory", func() {
		var (
			settings            *fakesettings.FakeSettingsService
			platform            *fakeplatform.FakePlatform
			infrastructure      *fakeinfrastructure.FakeInfrastructure
			blobstore           *fakeblobstore.FakeBlobstore
			taskService         *faketask.FakeService
			notifier            *fakenotif.FakeNotifier
			applier             *fakeappl.FakeApplier
			compiler            *fakecomp.FakeCompiler
			jobSupervisor       *fakejobsuper.FakeJobSupervisor
			specService         *fakeas.FakeV1Service
			drainScriptProvider boshdrain.DrainScriptProvider
			factory             Factory
			logger              boshlog.Logger
		)

		BeforeEach(func() {
			settings = &fakesettings.FakeSettingsService{}
			platform = fakeplatform.NewFakePlatform()
			infrastructure = fakeinfrastructure.NewFakeInfrastructure()
			blobstore = &fakeblobstore.FakeBlobstore{}
			taskService = &faketask.FakeService{}
			notifier = fakenotif.NewFakeNotifier()
			applier = fakeappl.NewFakeApplier()
			compiler = fakecomp.NewFakeCompiler()
			jobSupervisor = fakejobsuper.NewFakeJobSupervisor()
			specService = fakeas.NewFakeV1Service()
			drainScriptProvider = boshdrain.NewConcreteDrainScriptProvider(nil, nil, platform.GetDirProvider())
			logger = boshlog.NewLogger(boshlog.LEVEL_NONE)
		})

		JustBeforeEach(func() {
			factory = NewFactory(
				settings,
				platform,
				infrastructure,
				blobstore,
				taskService,
				notifier,
				applier,
				compiler,
				jobSupervisor,
				specService,
				drainScriptProvider,
				logger,
			)
		})

		It("new factory", func() {
			actions := []string{
				"apply",
				"drain",
				"fetch_logs",
				"get_task",
				"get_state",
				"list_disk",
				"migrate_disk",
				"mount_disk",
				"ping",
				"prepare_network_change",
				"ssh",
				"start",
				"stop",
				"unmount_disk",
				"compile_package",
				"release_apply_spec",
			}

			for _, actionName := range actions {
				action, err := factory.Create(actionName)
				Expect(err).NotTo(HaveOccurred())
				Expect(action).ToNot(BeNil())
			}

			action, err := factory.Create("gobberish")
			Expect(err).To(HaveOccurred())
			Expect(action).To(BeNil())
		})

		It("apply", func() {
			action, err := factory.Create("apply")
			Expect(err).NotTo(HaveOccurred())
			Expect(action).ToNot(BeNil())
			Expect(NewApply(applier, specService)).To(Equal(action))
		})

		It("drain", func() {
			action, err := factory.Create("drain")
			Expect(err).NotTo(HaveOccurred())
			Expect(action).ToNot(BeNil())
			Expect(NewDrain(notifier, specService, drainScriptProvider, jobSupervisor)).To(Equal(action))
		})

		It("fetch_logs", func() {
			action, err := factory.Create("fetch_logs")
			Expect(err).NotTo(HaveOccurred())
			Expect(action).ToNot(BeNil())
			Expect(NewLogs(platform.GetCompressor(), platform.GetCopier(), blobstore, platform.GetDirProvider())).To(Equal(action))
		})

		It("get_task", func() {
			action, err := factory.Create("get_task")
			Expect(err).NotTo(HaveOccurred())
			Expect(action).ToNot(BeNil())
			Expect(NewGetTask(taskService)).To(Equal(action))
		})

		It("get_state", func() {
			ntpService := boshntp.NewConcreteService(platform.GetFs(), platform.GetDirProvider())
			action, err := factory.Create("get_state")
			Expect(err).NotTo(HaveOccurred())
			Expect(action).ToNot(BeNil())
			Expect(NewGetState(settings, specService, jobSupervisor, platform.GetVitalsService(), ntpService)).To(Equal(action))
		})

		It("list_disk", func() {
			action, err := factory.Create("list_disk")
			Expect(err).NotTo(HaveOccurred())
			Expect(action).ToNot(BeNil())
			Expect(NewListDisk(settings, platform, logger)).To(Equal(action))
		})

		It("migrate_disk", func() {
			action, err := factory.Create("migrate_disk")
			Expect(err).NotTo(HaveOccurred())
			Expect(action).ToNot(BeNil())
			Expect(NewMigrateDisk(platform, platform.GetDirProvider())).To(Equal(action))
		})

		It("mount_disk", func() {
			action, err := factory.Create("mount_disk")
			Expect(err).NotTo(HaveOccurred())
			Expect(action).ToNot(BeNil())
			Expect(NewMountDisk(settings, infrastructure, platform, platform.GetDirProvider())).To(Equal(action))
		})

		It("prepare_network_change", func() {
			action, err := factory.Create("prepare_network_change")
			Expect(err).NotTo(HaveOccurred())
			Expect(action).ToNot(BeNil())
			Expect(NewPrepareNetworkChange(platform.GetFs(), settings)).To(Equal(action))
		})

		It("prepare_configure_networks", func() {
			action, err := factory.Create("prepare_configure_networks")
			Expect(err).NotTo(HaveOccurred())
			Expect(action).ToNot(BeNil())
			Expect(NewPrepareConfigureNetworks(platform.GetFs(), settings)).To(Equal(action))
		})

		It("configure_networks", func() {
			action, err := factory.Create("configure_networks")
			Expect(err).NotTo(HaveOccurred())
			Expect(action).ToNot(BeNil())
			Expect(NewConfigureNetworks()).To(Equal(action))
		})

		It("ssh", func() {
			action, err := factory.Create("ssh")
			Expect(err).NotTo(HaveOccurred())
			Expect(action).ToNot(BeNil())
			Expect(NewSsh(settings, platform, platform.GetDirProvider())).To(Equal(action))
		})

		It("start", func() {
			action, err := factory.Create("start")
			Expect(err).NotTo(HaveOccurred())
			Expect(action).ToNot(BeNil())
			Expect(NewStart(jobSupervisor)).To(Equal(action))
		})

		It("unmount_disk", func() {
			action, err := factory.Create("unmount_disk")
			Expect(err).NotTo(HaveOccurred())
			Expect(action).ToNot(BeNil())
			Expect(NewUnmountDisk(settings, platform)).To(Equal(action))
		})

		It("compile_package", func() {
			action, err := factory.Create("compile_package")
			Expect(err).NotTo(HaveOccurred())
			Expect(action).ToNot(BeNil())
			Expect(NewCompilePackage(compiler)).To(Equal(action))
		})
	})
}
	})

	It("get_task", func() {
		action, err := factory.Create("get_task")
		Expect(err).ToNot(HaveOccurred())
		Expect(action).To(Equal(NewGetTask(taskService)))
	})

	It("cancel_task", func() {
		action, err := factory.Create("cancel_task")
		Expect(err).ToNot(HaveOccurred())
		Expect(action).To(Equal(NewCancelTask(taskService)))
	})

	It("get_state", func() {
		ntpService := boshntp.NewConcreteService(platform.GetFs(), platform.GetDirProvider())
		action, err := factory.Create("get_state")
		Expect(err).ToNot(HaveOccurred())
		Expect(action).To(Equal(NewGetState(settingsService, specService, jobSupervisor, platform.GetVitalsService(), ntpService)))
	})

	It("list_disk", func() {
		action, err := factory.Create("list_disk")
		Expect(err).ToNot(HaveOccurred())
		Expect(action).To(Equal(NewListDisk(settingsService, platform, logger)))
	})

	It("migrate_disk", func() {
		action, err := factory.Create("migrate_disk")
		Expect(err).ToNot(HaveOccurred())
		Expect(action).To(Equal(NewMigrateDisk(platform, platform.GetDirProvider())))
示例#6
0
func init() {
	Describe("Testing with Ginkgo", func() {
		It("new factory", func() {
			actions := []string{
				"apply",
				"drain",
				"fetch_logs",
				"get_task",
				"get_state",
				"list_disk",
				"migrate_disk",
				"mount_disk",
				"ping",
				"prepare_network_change",
				"ssh",
				"start",
				"stop",
				"unmount_disk",
				"compile_package",
				"release_apply_spec",
			}

			_, factory := buildFactory()

			for _, actionName := range actions {
				action, err := factory.Create(actionName)
				assert.NoError(GinkgoT(), err)
				assert.NotNil(GinkgoT(), action)
			}

			action, err := factory.Create("gobberish")
			assert.Error(GinkgoT(), err)
			assert.Nil(GinkgoT(), action)
		})
		It("new factory apply", func() {

			deps, factory := buildFactory()
			action, err := factory.Create("apply")
			assert.NoError(GinkgoT(), err)
			assert.NotNil(GinkgoT(), action)
			assert.Equal(GinkgoT(), NewApply(deps.applier, deps.specService), action)
		})
		It("new factory drain", func() {

			deps, factory := buildFactory()
			action, err := factory.Create("drain")
			assert.NoError(GinkgoT(), err)
			assert.NotNil(GinkgoT(), action)
			assert.Equal(GinkgoT(), NewDrain(deps.notifier, deps.specService, deps.drainScriptProvider), action)
		})
		It("new factory fetch logs", func() {

			deps, factory := buildFactory()
			action, err := factory.Create("fetch_logs")
			assert.NoError(GinkgoT(), err)
			assert.NotNil(GinkgoT(), action)
			assert.Equal(GinkgoT(), NewLogs(deps.platform.GetCompressor(), deps.platform.GetCopier(), deps.blobstore, deps.platform.GetDirProvider()), action)
		})
		It("new factory get task", func() {

			deps, factory := buildFactory()
			action, err := factory.Create("get_task")
			assert.NoError(GinkgoT(), err)
			assert.NotNil(GinkgoT(), action)
			assert.Equal(GinkgoT(), NewGetTask(deps.taskService), action)
		})
		It("new factory get state", func() {

			deps, factory := buildFactory()
			ntpService := boshntp.NewConcreteService(deps.platform.GetFs(), deps.platform.GetDirProvider())
			action, err := factory.Create("get_state")
			assert.NoError(GinkgoT(), err)
			assert.NotNil(GinkgoT(), action)
			assert.Equal(GinkgoT(), NewGetState(deps.settings, deps.specService, deps.jobSupervisor, deps.platform.GetVitalsService(), ntpService), action)
		})
		It("new factory list disk", func() {

			deps, factory := buildFactory()
			action, err := factory.Create("list_disk")
			assert.NoError(GinkgoT(), err)
			assert.NotNil(GinkgoT(), action)
			assert.Equal(GinkgoT(), NewListDisk(deps.settings, deps.platform), action)
		})
		It("new factory migrate disk", func() {

			deps, factory := buildFactory()
			action, err := factory.Create("migrate_disk")
			assert.NoError(GinkgoT(), err)
			assert.NotNil(GinkgoT(), action)
			assert.Equal(GinkgoT(), NewMigrateDisk(deps.platform, deps.platform.GetDirProvider()), action)
		})
		It("new factory mount disk", func() {

			deps, factory := buildFactory()
			action, err := factory.Create("mount_disk")
			assert.NoError(GinkgoT(), err)
			assert.NotNil(GinkgoT(), action)
			assert.Equal(GinkgoT(), NewMountDisk(deps.settings, deps.platform, deps.platform.GetDirProvider()), action)
		})
		It("new factory ssh", func() {

			deps, factory := buildFactory()
			action, err := factory.Create("ssh")
			assert.NoError(GinkgoT(), err)
			assert.NotNil(GinkgoT(), action)
			assert.Equal(GinkgoT(), NewSsh(deps.settings, deps.platform, deps.platform.GetDirProvider()), action)
		})
		It("new factory start", func() {

			deps, factory := buildFactory()
			action, err := factory.Create("start")
			assert.NoError(GinkgoT(), err)
			assert.NotNil(GinkgoT(), action)
			assert.Equal(GinkgoT(), NewStart(deps.jobSupervisor), action)
		})
		It("new factory unmount disk", func() {

			deps, factory := buildFactory()
			action, err := factory.Create("unmount_disk")
			assert.NoError(GinkgoT(), err)
			assert.NotNil(GinkgoT(), action)
			assert.Equal(GinkgoT(), NewUnmountDisk(deps.settings, deps.platform), action)
		})
		It("new factory compile package", func() {

			deps, factory := buildFactory()
			action, err := factory.Create("compile_package")
			assert.NoError(GinkgoT(), err)
			assert.NotNil(GinkgoT(), action)
			assert.Equal(GinkgoT(), NewCompilePackage(deps.compiler), action)
		})
	})
}