コード例 #1
0
  public void testLookupCustomPackagesForChannel() throws Exception {
    Channel channel1 = ChannelFactoryTest.createTestChannel(user);
    Package pack = PackageTest.createTestPackage(user.getOrg());
    List test =
        PackageManager.lookupCustomPackagesForChannel(channel1.getId(), user.getOrg().getId());

    assertTrue(test.size() == 1);
    PackageOverview packOver = (PackageOverview) test.get(0);
    assertEquals(pack.getId(), packOver.getId());

    channel1.addPackage(pack);
    test = PackageManager.lookupCustomPackagesForChannel(channel1.getId(), user.getOrg().getId());

    assertTrue(test.size() == 0);
  }
コード例 #2
0
 public void testPossiblePackagesForPushingIntoChannel() throws Exception {
   Errata e = ErrataFactoryTest.createTestPublishedErrata(user.getOrg().getId());
   Channel c = ChannelTestUtils.createTestChannel(user);
   DataResult dr =
       PackageManager.possiblePackagesForPushingIntoChannel(c.getId(), e.getId(), null);
   assertTrue(dr.size() > 0);
 }
コード例 #3
0
  public void testSystemPackageList() throws Exception {
    // need a system
    // need to add packages to that system
    // then need to query those values
    PageControl pc = new PageControl();
    pc.setIndexData(false);
    pc.setStart(1);

    user.addRole(RoleFactory.ORG_ADMIN);

    Server server = ServerFactoryTest.createTestServer(user, true);
    PackageManagerTest.addPackageToSystemAndChannel(
        "test-package-name" + TestUtils.randomString(),
        server,
        ChannelFactoryTest.createTestChannel(user));

    DataResult dr = PackageManager.systemPackageList(server.getId(), pc);
    assertNotNull(dr);
    assertEquals(1, dr.size());

    for (Iterator itr = dr.iterator(); itr.hasNext(); ) {
      Object o = itr.next();
      assertTrue(o instanceof PackageListItem);
    }
  }
コード例 #4
0
  public void testPackageNameOverview() {
    String packageName = "kernel";
    String[] channelarches = {"channel-ia32", "channel-x86_64"};
    DataResult dr =
        PackageManager.lookupPackageNameOverview(user.getOrg(), packageName, channelarches);

    assertNotNull(dr);
  }
コード例 #5
0
 public void testGuestimateInvalidPackage() throws Exception {
   // guestimatePackageBySystem should return null if it
   // can't find a package, not throw an exception.
   try {
     assertNull(PackageManager.guestimatePackageBySystem(10000L, 100L, 100L, 0L, null));
   } catch (Exception e) {
     fail("method should return null");
   }
 }
コード例 #6
0
 public void testGetServerNeededUpdatePackageByName() throws Exception {
   user.addRole(RoleFactory.ORG_ADMIN);
   Server s = ServerFactoryTest.createTestServer(user);
   Channel c = ChannelFactoryTest.createTestChannel(user);
   addPackageToSystemAndChannel("some-test-package", s, c);
   // Not enough time actually test the results of this query for now
   // Just testing that it runs without SQL error. -mmccune
   assertNull(PackageManager.getServerNeededUpdatePackageByName(s.getId(), "some-test-package"));
 }
コード例 #7
0
  public void testVerCmp() {

    // epoch
    int result = testEpoch("1", "2");
    assertEquals(-1, result);

    result = testEpoch("2", "1");
    assertEquals(1, result);

    result = testEpoch(null, "1");
    assertEquals(-1, result);

    result = testEpoch("2", null);
    assertEquals(1, result);

    // version
    result = testVersion("1", "2");
    assertEquals(-1, result);

    result = testVersion("2", "1");
    assertEquals(1, result);

    result = testVersion(null, "1");
    assertEquals(-1, result);

    result = testVersion("1", null);
    assertEquals(1, result);

    // release
    result = testRelease("1", "2");
    assertEquals(-1, result);

    result = testRelease("2", "1");
    assertEquals(1, result);

    result = testRelease(null, "1");
    assertEquals(-1, result);

    result = testRelease("1", null);
    assertEquals(1, result);

    // make sure we test alpha-numerics through rpmVersionComparator
    result = testRelease("1.2b", "1.2c");
    assertEquals(-1, result);

    result = testRelease("1.2b3a", "1.2b2");
    assertEquals(1, result);

    // test all nulls
    result = testEpoch(null, null);
    assertEquals(0, result);

    // test equals
    result = PackageManager.verCmp("4", "2.1", "b3", "4", "2.1", "b3");
    assertEquals(0, result);
  }
コード例 #8
0
  // This test only works if you have Channels syched to your sat
  public void xxxxPackageNamesByCapability() throws Exception {

    /*user.addRole(RoleFactory.ORG_ADMIN);
    Channel c = ChannelFactoryTest.createTestChannel(user);
    Package pak = addPackageToChannel(user, TestUtils.randomString(), c);
    PackageCapability cap = PackageCapabilityTest.createTestCapability();*/
    DataResult dr =
        PackageManager.packageNamesByCapability(user.getOrg(), "rhn.kickstart.boot_image");
    assertNotNull(dr);
    assertTrue(dr.size() > 0);
  }
コード例 #9
0
  public void testRepodata() throws Exception {

    OutputStream st = new ByteArrayOutputStream();
    SimpleContentHandler tmpHandler = getTemporaryHandler(st);

    SimpleAttributesImpl attr = new SimpleAttributesImpl();
    attr.addAttribute("type", "rpm");
    tmpHandler.startDocument();

    tmpHandler.startElement("package", attr);

    SimpleAttributesImpl secattr = new SimpleAttributesImpl();
    attr.addAttribute("bar", "&>><<");
    tmpHandler.startElement("foo", secattr);
    tmpHandler.addCharacters("&&&&");
    tmpHandler.endElement("foo");

    tmpHandler.endElement("package");
    tmpHandler.endDocument();

    // st.flush();
    String test = st.toString();
    System.out.println(test);

    Package p = PackageTest.createTestPackage();
    Channel c = ChannelFactoryTest.createTestChannel();
    c.addPackage(p);
    ChannelFactory.save(c);

    PackageManager.createRepoEntrys(c.getId());

    PackageManager.updateRepoPrimary(p.getId(), test);
    DataResult dr = PackageManager.getRepoData(p.getId());
    PackageDto dto = (PackageDto) dr.get(0);
    String prim = dto.getPrimaryXml();
    String other = dto.getOtherXml();
    assertEquals(prim, test);
  }
コード例 #10
0
  public void testPackageNamesByCapabilityAndChannel() throws Exception {
    Channel channel1 = ChannelFactoryTest.createTestChannel(user);
    addKickstartPackageToChannel(ConfigDefaults.get().getKickstartPackageName(), channel1);

    // Add a regular non-kickstart package as well:
    PackageManagerTest.addPackageToChannel("Another package", channel1);

    DataResult dr =
        PackageManager.packageNamesByCapabilityAndChannel(
            user.getOrg(), BaseTreeEditOperation.KICKSTART_CAPABILITY, channel1);
    assertNotNull(dr);
    assertEquals(1, dr.size());
    PackageListItem item = (PackageListItem) dr.get(0);
    assertEquals(ConfigDefaults.get().getKickstartPackageName(), item.getName());
  }
コード例 #11
0
  public void testUpgradable() throws Exception {
    Map info =
        ErrataCacheManagerTest.createServerNeededPackageCache(user, ErrataFactory.ERRATA_TYPE_BUG);
    Server s = (Server) info.get("server");
    Package p = (Package) info.get("package");
    p = (Package) TestUtils.saveAndReload(p);

    DataResult<UpgradablePackageListItem> dr = PackageManager.upgradable(s.getId(), null);
    assertFalse(dr.isEmpty());
    boolean containsSamePackage = false;
    for (UpgradablePackageListItem item : dr) {
      if (p.getPackageName().getName().equals(item.getName())) {
        containsSamePackage = true;
      }
      assertTrue(item.getIdCombo().split("\\|").length == 3);
    }
    assertTrue(containsSamePackage);
  }
コード例 #12
0
  public void testDeletePackages() throws Exception {
    // Configuration
    final int numPackagesToDelete = 50;

    // Setup
    user.addRole(RoleFactory.ORG_ADMIN);

    Set<Long> doomedPackageIds = new HashSet<Long>(numPackagesToDelete);
    for (int ii = 0; ii < numPackagesToDelete; ii++) {
      Package pack = PackageTest.createTestPackage(user.getOrg());
      doomedPackageIds.add(pack.getId());
    }

    int numPackagesBeforeDelete = PackageFactory.lookupOrphanPackages(user.getOrg()).size();
    assertTrue(numPackagesBeforeDelete >= numPackagesToDelete);

    // Test
    PackageManager.deletePackages(doomedPackageIds, user);

    // Verify
    int numPackagesAfterDelete = PackageFactory.lookupOrphanPackages(user.getOrg()).size();
    assertEquals(numPackagesBeforeDelete - numPackagesToDelete, numPackagesAfterDelete);
  }
コード例 #13
0
  public void testUpgradablePackagesFromServerSet() throws Exception {
    // Setup
    User admin = UserTestUtils.findNewUser("ssmUpgradeUser1", "ssmUpgradeOrg1");
    Org org = admin.getOrg();

    //   Create the server and add to the SSM
    Server server = ServerTestUtils.createTestSystem(admin);
    ServerTestUtils.addServersToSsm(admin, server.getId());

    //   Create upgraded package EVR so package will show up from the query
    PackageEvr upgradedPackageEvr = PackageEvrFactory.createPackageEvr("1", "1.0.0", "2");
    upgradedPackageEvr = (PackageEvr) TestUtils.saveAndReload(upgradedPackageEvr);

    ServerTestUtils.populateServerErrataPackages(
        org, server, upgradedPackageEvr, ErrataFactory.ERRATA_TYPE_SECURITY);
    ServerTestUtils.populateServerErrataPackages(
        org, server, upgradedPackageEvr, ErrataFactory.ERRATA_TYPE_BUG);

    // Test
    DataResult result = PackageManager.upgradablePackagesFromServerSet(admin);

    assertTrue(result != null);
    assertEquals(2, result.size());
  }
コード例 #14
0
  /** {@inheritDoc} */
  @Override
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {

    RequestContext requestContext = new RequestContext(request);
    User user = requestContext.getCurrentUser();

    long cid = requestContext.getRequiredParam(RequestContext.CID);
    Channel chan = ChannelFactory.lookupByIdAndUser(cid, user);
    String syncType = request.getParameter(SYNC_TYPE);

    if (!UserManager.verifyChannelAdmin(user, chan)) {
      throw new PermissionException(RoleFactory.CHANNEL_ADMIN);
    }
    if (chan.getOrg() == null) {
      throw new PermissionCheckFailureException();
    }

    String selectedChan = request.getParameter(SELECTED_CHANNEL);
    request.setAttribute(RequestContext.CID, chan.getId());
    request.setAttribute(CHANNEL_NAME, chan.getName());

    if (requestContext.wasDispatched("channel.jsp.package.mergebutton")) {
      Map<String, Object> params = new HashMap<String, Object>();
      params.put(RequestContext.CID, cid);
      params.put(OTHER_ID, selectedChan);
      params.put(SYNC_TYPE, syncType);
      return getStrutsDelegate()
          .forwardParams(mapping.findForward(RhnHelper.CONFIRM_FORWARD), params);
    }

    // selected channel id
    long scid = 0;
    String sname = "";

    // If a channel isn't selected, select one smartly
    if (selectedChan == null) {
      if (chan.isCloned()) {
        scid = chan.getOriginal().getId();
      }
    } else if (!NO_PACKAGES.equals(selectedChan)) {
      scid = Long.parseLong(selectedChan);
    }

    // Add Red Hat Base Channels, and custom base channels to the list, and if one
    //      is selected, select it
    List<SelectableChannel> chanList = findChannels(user, scid);
    DataResult result = null;

    if (scid != 0) {
      sname = ChannelFactory.lookupByIdAndUser(scid, user).getName();

      result = PackageManager.comparePackagesBetweenChannels(cid, scid);

      TagHelper.bindElaboratorTo(listName, result.getElaborator(), request);
    }

    request.setAttribute(CHANNEL_LIST, chanList);
    request.setAttribute(OTHER_CHANNEL, sname);
    request.setAttribute(SYNC_TYPE, syncType);
    request.setAttribute(ListTagHelper.PARENT_URL, request.getRequestURI());
    request.setAttribute(RequestContext.PAGE_LIST, result);

    return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
  }
コード例 #15
0
  public void testPackageIdsInSet() throws Exception {

    DataResult dr = PackageManager.packageIdsInSet(user, "packages_to_add", new PageControl());

    assertNotNull(dr);
  }
コード例 #16
0
 private int testEpoch(String e1, String e2) {
   return PackageManager.verCmp(e1, null, null, e2, null, null);
 }
コード例 #17
0
 private int testVersion(String v1, String v2) {
   return PackageManager.verCmp("1", v1, null, "1", v2, null);
 }
コード例 #18
0
  /** {@inheritDoc} */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {

    RequestContext requestContext = new RequestContext(request);
    User user = requestContext.getLoggedInUser();

    // If this is an easy one and we have the pid
    if (request.getParameter("pid") != null) {
      long pid = requestContext.getRequiredParam("pid");
      Package pkg = PackageFactory.lookupByIdAndUser(pid, user);

      // show permission error if pid is invalid like we did before
      if (pkg == null) {
        throw new PermissionException("Invalid pid");
      }

      if (pkg instanceof Patch) {
        request.setAttribute("type", "patch");
        request.setAttribute(PACKAGE_NAME, pkg.getPackageName().getName());
        request.setAttribute(
            "readme_url", DownloadManager.getPatchReadmeDownloadPath((Patch) pkg, user));
      } else if (pkg instanceof PatchSet) {
        request.setAttribute("type", "patchset");
        request.setAttribute(PACKAGE_NAME, pkg.getNameEvra());
        request.setAttribute(
            "readme_url", DownloadManager.getPatchSetReadmeDownloadPath((PatchSet) pkg, user));
      } else {
        request.setAttribute("type", "rpm");
        request.setAttribute(PACKAGE_NAME, pkg.getFilename());
        if (!pkg.getPackageKeys().isEmpty()) {
          request.setAttribute(PACKAGE_KEY, pkg.getPackageKeys().iterator().next().getKey());
        }
        boolean isDebug = pkg.getPackageName().getName().contains("debuginfo");

        request.setAttribute("isDebuginfo", isDebug);
        if (!isDebug) {
          Package debugPkg = PackageManager.findDebugInfo(user, pkg);
          String ftpUrl = PackageManager.generateFtpDebugPath(pkg);
          if (debugPkg != null) {
            request.setAttribute(
                "debugUrl", DownloadManager.getPackageDownloadPath(debugPkg, user));
          } else if (ftpUrl != null) {
            request.setAttribute("debugUrl", ftpUrl);
            request.setAttribute("debugFtp", true);
          }
        }
      }

      if (DownloadManager.isFileAvailable(pkg.getPath())) {
        request.setAttribute("url", DownloadManager.getPackageDownloadPath(pkg, user));
      }

      List<PackageSource> src = PackageFactory.lookupPackageSources(pkg);

      if (!src.isEmpty() && DownloadManager.isFileAvailable(src.get(0).getPath())) {
        request.setAttribute(
            "srpm_url", DownloadManager.getPackageSourceDownloadPath(pkg, src.get(0), user));
        request.setAttribute("srpm_path", src.get(0).getFile());
      }

      request.setAttribute("pack", pkg);
      // description can be null.
      if (pkg.getDescription() != null) {
        request.setAttribute("description", pkg.getDescription().replace("\n", "<BR>\n"));
      } else {
        request.setAttribute("description", pkg.getDescription());
      }
      request.setAttribute("packArches", PackageFactory.findPackagesWithDifferentArch(pkg));
      request.setAttribute("pid", pid);

      return mapping.findForward("default");
    } else { // we have to guess
      PackageListItem item = PackageListItem.parse(request.getParameter("id_combo"));
      Package pkg;
      long nameId = item.getIdOne();
      long evrId = item.getIdTwo();
      long archId = 0;
      if (item.getIdThree() != null) {
        archId = item.getIdThree();
      }

      Long cid = requestContext.getParamAsLong("cid");
      Long sid = requestContext.getParamAsLong("sid");
      if (cid != null) {
        pkg = PackageManager.guestimatePackageByChannel(cid, nameId, evrId, user.getOrg());

      } else if (sid != null) {
        pkg = PackageManager.guestimatePackageBySystem(sid, nameId, evrId, archId, user.getOrg());

      } else {
        throw new BadParameterException("pid, cid, or sid");
      }

      // show permission error if pid is invalid like we did before
      if (pkg == null) {
        throw new NoSuchPackageException();
      }

      Map params = new HashMap();
      params.put("pid", pkg.getId());
      return getStrutsDelegate().forwardParams(mapping.findForward("package"), params);
    }
  }
コード例 #19
0
 private int testRelease(String r1, String r2) {
   return PackageManager.verCmp("1", "2", r1, "1", "2", r2);
 }
コード例 #20
0
  // Check to make sure up2date is 2.9.0
  protected ValidatorError validateUp2dateVersion() {
    Server hostServer = getHostServer();
    List packages = PackageManager.systemPackageList(hostServer.getId(), null);
    if (packages != null) {
      log.debug("    packages.size() : " + packages.size());
    }
    // PackageListItem
    Iterator i = packages.iterator();
    String up2dateepoch = null;
    String up2dateversion = null;
    String up2daterelease = null;

    while (i.hasNext()) {
      PackageListItem pli = (PackageListItem) i.next();
      if (pli.getName().equals("yum-rhn-plugin")) {
        // found yum-rhn-plugin - returning
        return null;
      }
      if (pli.getName().equals("zypp-plugin-spacewalk")) {
        // found zypp-plugin-spacewalk - returning
        return null;
      }

      if (pli.getName().equals("up2date")) {
        log.debug("    found up2date ...");
        up2dateepoch = pli.getEpoch();
        up2dateversion = pli.getVersion();
        up2daterelease = pli.getRelease();

        log.debug("    e: " + up2dateepoch + " v: " + up2dateversion + " r : " + up2daterelease);
      }
    }

    if (up2dateepoch == null && up2dateversion == null && up2daterelease == null) {
      Object[] args = new Object[2];
      args[0] = hostServer.getId();
      args[1] = hostServer.getName();
      return new ValidatorError("kickstart.schedule.noup2date", args);
    }

    up2dateepoch = up2dateepoch == null ? "0" : up2dateepoch;
    up2dateversion = up2dateversion == null ? "0" : up2dateversion;
    up2daterelease = up2daterelease == null ? "0" : up2daterelease;

    int comp =
        PackageManager.verCmp(
            up2dateepoch, up2dateversion, up2daterelease, "0", UP2DATE_VERSION, "0");
    log.debug("    Got back comp from verCmp: " + comp);
    if (comp < 0) {
      Long packageId =
          PackageManager.getServerNeededUpdatePackageByName(hostServer.getId(), "up2date");
      if (packageId == null) {
        Object[] args = new Object[2];
        args[0] = UP2DATE_VERSION;
        args[1] = up2dateversion;
        return new ValidatorError("kickstart.schedule.noup2dateinchannel", args);
      }
      Package p = PackageFactory.lookupByIdAndUser(packageId, this.user);

      Map evrmap = new HashMap();
      evrmap.put("name_id", p.getPackageName().getId());
      evrmap.put("evr_id", p.getPackageEvr().getId());
      evrmap.put("arch_id", p.getPackageArch().getId());
      packagesToInstall.add(evrmap);
    } else {
      return null;
    }

    return null;
  }
コード例 #21
0
 public void testGuestimateHandlesNullArchId() throws Exception {
   PackageListItem pli = PackageListItem.parse("10000|1000");
   assertNull(pli.getIdThree());
   assertNull(
       PackageManager.guestimatePackageBySystem(10000L, 100L, 100L, pli.getIdThree(), null));
 }