def test_vsphere(self): '''Success Test module get_data() forcing VSPHERE.''' _write_cloud_info_file('VSPHERE') dsrc = DataSourceAltCloud({}, None, self.paths) dsrc.user_data_vsphere = lambda: True self.assertEquals(True, dsrc.get_data())
def test_fail_rhev(self): '''Failure Test module get_data() forcing RHEV.''' _write_cloud_info_file('RHEV') dsrc = DataSourceAltCloud({}, None, self.paths) dsrc.user_data_rhevm = lambda: False self.assertEquals(False, dsrc.get_data())
def test_rhev(self): '''Success Test module get_data() forcing RHEV.''' _write_cloud_info_file('RHEV') dsrc = DataSourceAltCloud({}, None, self.paths) dsrc.user_data_rhevm = lambda: True self.assertEquals(True, dsrc.get_data())
def test_fail_vsphere(self): '''Failure Test module get_data() forcing VSPHERE.''' _write_cloud_info_file('VSPHERE') dsrc = DataSourceAltCloud({}, None, self.paths) dsrc.user_data_vsphere = lambda: False self.assertEquals(False, dsrc.get_data())
def test_rhev_no_cloud_file(self): '''Test No cloud info file module get_data() forcing RHEV.''' util.read_dmi_data = _dmi_data('RHEV Hypervisor') dsrc = DataSourceAltCloud({}, None, self.paths) dsrc.user_data_rhevm = lambda: True self.assertEquals(True, dsrc.get_data())
def test_failure_no_cloud_file(self): '''Test No cloud info file module get_data() forcing unrecognized.''' cloudinit.sources.DataSourceAltCloud.CMD_DMI_SYSTEM = \ ['echo', 'Unrecognized Platform'] dsrc = DataSourceAltCloud({}, None, self.paths) self.assertEquals(False, dsrc.get_data())
def test_rhev_no_cloud_file(self): '''Test No cloud info file module get_data() forcing RHEV.''' util.read_dmi_data = _dmi_data('RHEV Hypervisor') dsrc = DataSourceAltCloud({}, None, self.paths) dsrc.user_data_rhevm = lambda: True self.assertEqual(True, dsrc.get_data())
def test_vsphere_no_cloud_file(self): '''Test No cloud info file module get_data() forcing VSPHERE.''' util.read_dmi_data = _dmi_data('VMware Virtual Platform') dsrc = DataSourceAltCloud({}, None, self.paths) dsrc.user_data_vsphere = lambda: True self.assertEquals(True, dsrc.get_data())
def test_vsphere_no_cloud_file(self): '''Test No cloud info file module get_data() forcing VSPHERE.''' util.read_dmi_data = _dmi_data('VMware Virtual Platform') dsrc = DataSourceAltCloud({}, None, self.paths) dsrc.user_data_vsphere = lambda: True self.assertEqual(True, dsrc.get_data())
def test_rhev(self): ''' Test method get_cloud_type() for RHEVm systems. Forcing read_dmi_data return to match a RHEVm system: RHEV Hypervisor ''' util.read_dmi_data = _dmi_data('RHEV') dsrc = DataSourceAltCloud({}, None, self.paths) self.assertEqual('RHEV', dsrc.get_cloud_type())
def test_unknown(self): ''' Test method get_cloud_type() for unknown systems. Forcing read_dmi_data return to match an unrecognized return. ''' util.read_dmi_data = _dmi_data('Unrecognized Platform') dsrc = DataSourceAltCloud({}, None, self.paths) self.assertEqual('UNKNOWN', dsrc.get_cloud_type())
def test_vsphere_no_cloud_file(self): '''Test No cloud info file module get_data() forcing VSPHERE.''' cloudinit.sources.DataSourceAltCloud.CMD_DMI_SYSTEM = \ ['echo', 'VMware Virtual Platform'] dsrc = DataSourceAltCloud({}, None, self.paths) dsrc.user_data_vsphere = lambda: True self.assertEquals(True, dsrc.get_data())
def test_rhev_no_cloud_file(self): '''Test No cloud info file module get_data() forcing RHEV.''' cloudinit.sources.DataSourceAltCloud.CMD_DMI_SYSTEM = \ ['echo', 'RHEV Hypervisor'] dsrc = DataSourceAltCloud({}, None, self.paths) dsrc.user_data_rhevm = lambda: True self.assertEquals(True, dsrc.get_data())
def test_vsphere(self): ''' Test method get_cloud_type() for vSphere systems. Forcing read_dmi_data return to match a vSphere system: RHEV Hypervisor ''' util.read_dmi_data = _dmi_data('VMware Virtual Platform') dsrc = DataSourceAltCloud({}, None, self.paths) self.assertEqual('VSPHERE', dsrc.get_cloud_type())
def test_user_data_vsphere(self): '''Test user_data_vsphere() where mount_cb fails.''' cloudinit.sources.DataSourceAltCloud.MEDIA_DIR = self.mount_dir dsrc = DataSourceAltCloud({}, None, self.paths) self.assertEquals(False, dsrc.user_data_vsphere())
def test_no_modprobe_cmd(self): '''Test user_data_rhevm() with no modprobe command.''' cloudinit.sources.DataSourceAltCloud.CMD_PROBE_FLOPPY = \ ['bad command', 'modprobe floppy'] dsrc = DataSourceAltCloud({}, None, self.paths) self.assertEquals(False, dsrc.user_data_rhevm())
def test_modprobe_fails(self): '''Test user_data_rhevm() where modprobe fails.''' cloudinit.sources.DataSourceAltCloud.CMD_PROBE_FLOPPY = \ ['ls', 'modprobe floppy'] dsrc = DataSourceAltCloud({}, None, self.paths) self.assertEquals(False, dsrc.user_data_rhevm())
def test_udevadm_fails(self): '''Test user_data_rhevm() where udevadm fails.''' cloudinit.sources.DataSourceAltCloud.CMD_UDEVADM_SETTLE = \ ['ls', 'udevadm floppy'] dsrc = DataSourceAltCloud({}, None, self.paths) self.assertEquals(False, dsrc.user_data_rhevm())
def test_no_udevadm_cmd(self): '''Test user_data_rhevm() with no udevadm command.''' cloudinit.sources.DataSourceAltCloud.CMD_UDEVADM_SETTLE = \ ['bad command', 'udevadm floppy'] dsrc = DataSourceAltCloud({}, None, self.paths) self.assertEquals(False, dsrc.user_data_rhevm())
def test_exception2(self): ''' Test method get_cloud_type() where command dmidecode is not available. ''' cloudinit.sources.DataSourceAltCloud.CMD_DMI_SYSTEM = \ ['bad command'] dsrc = DataSourceAltCloud({}, None, self.paths) self.assertEquals('UNKNOWN', \ dsrc.get_cloud_type())
def test_unknown(self): ''' Test method get_cloud_type() for unknown systems. Forcing dmidecode return to match an unrecognized return. ''' cloudinit.sources.DataSourceAltCloud.CMD_DMI_SYSTEM = \ ['echo', 'Unrecognized Platform'] dsrc = DataSourceAltCloud({}, None, self.paths) self.assertEquals('UNKNOWN', \ dsrc.get_cloud_type())
def test_vsphere(self): ''' Test method get_cloud_type() for vSphere systems. Forcing dmidecode return to match a vSphere system: RHEV Hypervisor ''' cloudinit.sources.DataSourceAltCloud.CMD_DMI_SYSTEM = \ ['echo', 'VMware Virtual Platform'] dsrc = DataSourceAltCloud({}, None, self.paths) self.assertEquals('VSPHERE', \ dsrc.get_cloud_type())
def test_rhev(self): ''' Test method get_cloud_type() for RHEVm systems. Forcing dmidecode return to match a RHEVm system: RHEV Hypervisor ''' cloudinit.sources.DataSourceAltCloud.CMD_DMI_SYSTEM = \ ['echo', 'RHEV Hypervisor'] dsrc = DataSourceAltCloud({}, None, self.paths) self.assertEquals('RHEV', \ dsrc.get_cloud_type())
def test_no_modprobe_cmd(self): '''Test user_data_rhevm() with no modprobe command.''' self.m_modprobe_floppy.side_effect = subp.ProcessExecutionError( "No such file or dir") dsrc = dsac.DataSourceAltCloud({}, None, self.paths) self.assertEqual(False, dsrc.user_data_rhevm())
def test_unrecognized(self): '''Failure Test module get_data() forcing unrecognized.''' util.write_file(self.cloud_info_file, 'unrecognized') dsrc = dsac.DataSourceAltCloud({}, None, self.paths) with mock.patch.object(dsac, 'CLOUD_INFO_FILE', self.cloud_info_file): self.assertEqual(False, dsrc.get_data())
def test_user_data_vsphere_no_cdrom(self, m_mount_cb, m_find_devs_with): '''Test user_data_vsphere() where mount_cb fails.''' m_mount_cb.return_value = [] dsrc = dsac.DataSourceAltCloud({}, None, self.paths) self.assertEqual(False, dsrc.user_data_vsphere()) self.assertEqual(0, m_mount_cb.call_count)
def test_udevadm_fails(self): '''Test user_data_rhevm() where udevadm fails.''' self.m_udevadm_settle.side_effect = subp.ProcessExecutionError( "Failed settle.") dsrc = dsac.DataSourceAltCloud({}, None, self.paths) self.assertEqual(False, dsrc.user_data_rhevm())
def test_rhev_no_cloud_file(self): """Test No cloud info file module get_data() forcing RHEV.""" dmi.read_dmi_data = _dmi_data("RHEV Hypervisor") dsrc = dsac.DataSourceAltCloud({}, None, self.paths) dsrc.user_data_rhevm = lambda: True self.assertEqual(True, dsrc.get_data())
def test_modprobe_fails(self): '''Test user_data_rhevm() where modprobe fails.''' self.m_modprobe_floppy.side_effect = subp.ProcessExecutionError( "Failed modprobe") dsrc = dsac.DataSourceAltCloud({}, None, self.paths) self.assertEqual(False, dsrc.user_data_rhevm())
def test_cloud_info_file(self): """Return uppercase stripped content from /etc/sysconfig/cloud-info.""" dsrc = dsac.DataSourceAltCloud({}, None, self.paths) cloud_info = self.tmp_path('cloud-info', dir=self.tmp) util.write_file(cloud_info, ' OverRiDdeN CloudType ') # Attempting to read the directory generates IOError with mock.patch.object(dsac, 'CLOUD_INFO_FILE', cloud_info): self.assertEqual('OVERRIDDEN CLOUDTYPE', dsrc.get_cloud_type())
def test_fail_vsphere(self): '''Failure Test module get_data() forcing VSPHERE.''' util.write_file(self.cloud_info_file, 'VSPHERE') dsrc = dsac.DataSourceAltCloud({}, None, self.paths) dsrc.user_data_vsphere = lambda: False with mock.patch.object(dsac, 'CLOUD_INFO_FILE', self.cloud_info_file): self.assertEqual(False, dsrc.get_data())
def test_fail_rhev(self): """Failure Test module get_data() forcing RHEV.""" util.write_file(self.cloud_info_file, "RHEV") dsrc = dsac.DataSourceAltCloud({}, None, self.paths) dsrc.user_data_rhevm = lambda: False with mock.patch.object(dsac, "CLOUD_INFO_FILE", self.cloud_info_file): self.assertEqual(False, dsrc.get_data())
def test_callback_non_dc(self): '''Test read_user_data_callback() with only non-DC file.''' _remove_user_data_files(self.mount_dir, dc_file=True, non_dc_file=False) self.assertEqual('test user data', dsac.read_user_data_callback(self.mount_dir))
def test_failure_no_cloud_file(self): '''Test No cloud info file module get_data() forcing unrecognized.''' util.read_dmi_data = _dmi_data('Unrecognized Platform') dsrc = DataSourceAltCloud({}, None, self.paths) self.assertEquals(False, dsrc.get_data())
def test_callback_both(self): '''Test read_user_data_callback() with both files.''' self.assertEqual('test user data', dsac.read_user_data_callback(self.mount_dir))
def test_callback_none(self): '''Test read_user_data_callback() no files are found.''' _remove_user_data_files(self.mount_dir) self.assertIsNone(dsac.read_user_data_callback(self.mount_dir))
def test_unrecognized(self): '''Failure Test module get_data() forcing unrecognized.''' _write_cloud_info_file('unrecognized') dsrc = DataSourceAltCloud({}, None, self.paths) self.assertEquals(False, dsrc.get_data())