def test_create_notifications(self): self.useFixture(EnvironmentVariable("SNAP", "/snap/maas/current")) snap_common_path = Path(self.make_dir()) self.useFixture( EnvironmentVariable("SNAP_COMMON", str(snap_common_path)) ) snap_common_path.joinpath("snap_mode").write_text("all", "utf-8") sync_deprecation_notifications() notification1, notification2 = Notification.objects.order_by("ident") self.assertEqual(notification1.ident, "deprecation_MD1_admins") self.assertEqual(notification1.category, "warning") self.assertFalse(notification1.dismissable) self.assertTrue(notification1.admins) self.assertFalse(notification1.users) self.assertIn( "https://maas.io/deprecations/MD1", notification1.message ) self.assertNotIn( "Please contact your MAAS administrator.", notification1.message ) self.assertEqual(notification2.ident, "deprecation_MD1_users") self.assertEqual(notification2.category, "warning") self.assertFalse(notification2.dismissable) self.assertFalse(notification2.admins) self.assertTrue(notification2.users) self.assertIn( "Please contact your MAAS administrator.", notification2.message )
def test_deprecation_notices_snap_not_all_mode(self): self.useFixture(EnvironmentVariable("SNAP", "/snap/maas/current")) snap_common_path = Path(self.make_dir()) self.useFixture( EnvironmentVariable("SNAP_COMMON", str(snap_common_path))) snap_common_path.joinpath("snap_mode").write_text( "region+rack", "utf-8") self.assertEqual(get_deprecations(), [])
def test_deprecation_notices_snap_not_all_mode(self): self.useFixture(EnvironmentVariable("SNAP", "/snap/maas/current")) snap_common_path = Path(self.make_dir()) self.useFixture( EnvironmentVariable("SNAP_COMMON", str(snap_common_path))) snap_common_path.joinpath("snap_mode").write_text( "region+rack", "utf-8") handler = GeneralHandler(factory.make_User(), {}, None) self.assertEqual(handler.deprecation_notices({}), [])
def test_deprecation_notices_snap_all_mode(self): self.useFixture(EnvironmentVariable("SNAP", "/snap/maas/current")) snap_common_path = Path(self.make_dir()) self.useFixture( EnvironmentVariable("SNAP_COMMON", str(snap_common_path))) snap_common_path.joinpath("snap_mode").write_text("all", "utf-8") [notice] = get_deprecations() self.assertEqual(notice["id"], "MD1") self.assertEqual(notice["since"], "2.8") self.assertEqual(notice["url"], "https://maas.io/deprecations/MD1")
def test_deprecation_notices_snap_all_mode(self): self.useFixture(EnvironmentVariable("SNAP", "/snap/maas/current")) snap_common_path = Path(self.make_dir()) self.useFixture( EnvironmentVariable("SNAP_COMMON", str(snap_common_path))) snap_common_path.joinpath("snap_mode").write_text("all", "utf-8") handler = GeneralHandler(factory.make_User(), {}, None) [notice] = handler.deprecation_notices({}) self.assertEqual(notice["id"], "MD1") self.assertEqual(notice["since"], "2.8")
def _setup_environment(self): self.useFixture(EnvironmentVariable( 'ALTERNATIVE_CPIM_SERVICE_NAME', 'com.canonical.test.pim')) self.useFixture(EnvironmentVariable( 'FOLKS_BACKEND_PATH', os.path.join(get_service_library_path(), 'dummy.so'))) self.useFixture(EnvironmentVariable('FOLKS_BACKENDS_ALLOWED', 'dummy')) self.useFixture(EnvironmentVariable('FOLKS_PRIMARY_STORE', 'dummy')) self.useFixture(EnvironmentVariable( 'ADDRESS_BOOK_SERVICE_DEMO_DATA', self._get_vcard_location()))
def test_get_maas_cert_tuple(self): certs_dir = self.tempdir / "etc/maas/certificates" certs_dir.mkdir(parents=True) (certs_dir / "maas.crt").touch() (certs_dir / "maas.key").touch() self.useFixture(EnvironmentVariable("MAAS_ROOT", str(self.tempdir))) self.useFixture(EnvironmentVariable("SNAP", None)) self.assertEqual( get_maas_cert_tuple(), ( f"{certs_dir}/maas.crt", f"{certs_dir}/maas.key", ), )
def test_get_maas_cert_tuple_snap(self): certs_dir = self.tempdir / "certificates" certs_dir.mkdir(parents=True) (certs_dir / "maas.crt").touch() (certs_dir / "maas.key").touch() self.useFixture(EnvironmentVariable("SNAP_COMMON", str(self.tempdir))) self.useFixture(EnvironmentVariable("SNAP", "/snap/maas/current")) self.assertEqual( get_maas_cert_tuple(), ( f"{certs_dir}/maas.crt", f"{certs_dir}/maas.key", ), )
def setUp(self): super().setUp() # These steps need to happen in the right order otherwise they won't # get cleaned up properly and we'll be left in an incorrect timezone. self.addCleanup(time.tzset) self.useFixture(EnvironmentVariable('TZ', self._timezone)) time.tzset()
def _write_snap_mode(self, mode): snap_common_path = Path(self.make_dir()) snap_mode_path = snap_common_path.joinpath("snap_mode") if mode is not None: snap_mode_path.write_text(mode, "utf-8") self.useFixture( EnvironmentVariable("SNAP_COMMON", str(snap_common_path)))
def setUp(self): if is_process_running(INDICATOR_NETWORK): _stop_process(INDICATOR_NETWORK) self.addCleanup(_start_process, INDICATOR_NETWORK) ctv_tmpl = os.path.join(os.path.dirname(__file__), 'connectivity.py') (self.ctv_mock, self.obj_ctv) = self.spawn_server_template( ctv_tmpl, parameters=self.connectivity_parameters, stdout=subprocess.PIPE) self.ctv_private = dbus.Interface( self.session_con.get_object(CTV_IFACE, CTV_PRIV_OBJ), 'org.freedesktop.DBus.Properties') self.ctv_nets = dbus.Interface( self.session_con.get_object(CTV_IFACE, CTV_NETS_OBJ), 'org.freedesktop.DBus.Properties') inetwork = os.path.join(os.path.dirname(__file__), 'indicatornetwork.py') (self.inetwork_mock, self.obj_inetwork) = self.spawn_server_template( inetwork, parameters=self.indicatornetwork_parameters, stdout=subprocess.PIPE) # Required since this test needs to dismiss the OSK. self.useFixture(EnvironmentVariable("UITK_USE_MALIIT", "1")) super(UbuntuSystemSettingsHotspotTestCase, self).setUp()
def test_log_deprecations(self): self.useFixture(EnvironmentVariable("SNAP", "/snap/maas/current")) snap_common_path = Path(self.make_dir()) self.useFixture( EnvironmentVariable("SNAP_COMMON", str(snap_common_path))) snap_common_path.joinpath("snap_mode").write_text("all", "utf-8") events = [] logger = LegacyLogger(observer=events.append) log_deprecations(logger=logger) [event] = events self.assertEqual( event["_message_0"], "Deprecation MD1 (https://maas.io/deprecations/MD1): " "MAAS is currently running the PostgreSQL database inside the snap. " "It should be migrated outside of the snap.", )
def setUp(self): """Mock account service dbus, go to background page""" # mock ubuntu art directory using a local path art_dir = '%s/../background_images/' % (os.path.dirname( os.path.realpath(__file__))) user_obj = '/user/foo' self.user_props = { 'BackgroundFile': dbus.String('%slaunchpad.jpg' % art_dir, variant_level=1) } # start dbus system bus self.mock_server = self.spawn_server(ACCOUNTS_IFACE, ACCOUNTS_OBJ, ACCOUNTS_IFACE, system_bus=True, stdout=subprocess.PIPE) sleep(2) # create account proxy self.acc_proxy = dbus.Interface( self.dbus_con.get_object(ACCOUNTS_IFACE, ACCOUNTS_OBJ), dbusmock.MOCK_IFACE) # let accountservice find a user object path self.acc_proxy.AddMethod(ACCOUNTS_IFACE, 'FindUserById', 'x', 'o', 'ret = "%s"' % user_obj) # add getter and setter to mock self.acc_proxy.AddMethods( 'org.freedesktop.DBus.Properties', [('Get', 's', 'v', 'ret = self.user_props[args[0]]'), ('Set', 'sv', '', 'self.user_props[args[0]] = args[1]')]) # add user object to mock self.acc_proxy.AddObject( user_obj, ACCOUNTS_USER_IFACE, self.user_props, [('SetBackgroundFile', 'v', '', 'self.Set("%s", "BackgroundFile", args[0]);' % ACCOUNTS_USER_IFACE), ('GetBackgroundFile', '', 'v', 'ret = self.Get("%s", "BackgroundFile")' % ACCOUNTS_USER_IFACE)]) # create user proxy self.user_proxy = dbus.Interface( self.dbus_con.get_object(ACCOUNTS_IFACE, user_obj), ACCOUNTS_USER_IFACE) # patch env variable self.useFixture( EnvironmentVariable('SYSTEM_SETTINGS_UBUNTU_ART_DIR', art_dir)) super(BackgroundBaseTestCase, self).setUp('background') self.assertThat(self.main_view.background_page.active, Eventually(Equals(True)))
def test_log_deprecations(self): self.useFixture(EnvironmentVariable("SNAP", "/snap/maas/current")) snap_common_path = Path(self.make_dir()) self.useFixture( EnvironmentVariable("SNAP_COMMON", str(snap_common_path)) ) snap_common_path.joinpath("snap_mode").write_text("all", "utf-8") events = [] logger = LegacyLogger(observer=events.append) log_deprecations(logger=logger) [event] = events self.assertEqual( event["_message_0"], "Deprecation MD1 (https://maas.io/deprecations/MD1): " "The setup for this MAAS is deprecated and not suitable for production " "environments, as the database is running inside the snap.", )